diff --git a/backend/question-service/controllers/historyController.ts b/backend/question-service/controllers/historyController.ts index 3c596c42aa..e982739d09 100644 --- a/backend/question-service/controllers/historyController.ts +++ b/backend/question-service/controllers/historyController.ts @@ -17,19 +17,24 @@ export const getUserHistoryEntries = async (req: any, res: Response) => { model: "category", }, }); - + historyEntries.forEach(async (entry) => { if (entry.question === null) { await historyEntryModel.findByIdAndDelete({_id: entry._id}); } }) + const historyViewModels = historyEntries .filter((entry) => !(entry.question === null)) .map((entry) => { + const attemptStartDate = new Date(entry.attemptStartedAt); + const timeDiffMs = Date.now() - attemptStartDate.getTime(); + const isWithin24Hours = timeDiffMs < 86400000; // 1 Day; Same as ROOM_LIFESPAN in MatchingService. Can be different if desired. + return { id: entry._id, key: entry._id, - roomId: entry.roomId, + roomId: isWithin24Hours ? entry.roomId : null, attemptStartedAt: entry.attemptStartedAt.getTime(), lastAttemptSubmittedAt: entry.lastAttemptSubmittedAt.getTime(), title: entry.question.title, diff --git a/frontend/src/domain/entities/HistoryEntry.ts b/frontend/src/domain/entities/HistoryEntry.ts index c103498618..1b492142d8 100644 --- a/frontend/src/domain/entities/HistoryEntry.ts +++ b/frontend/src/domain/entities/HistoryEntry.ts @@ -1,7 +1,7 @@ export interface HistoryEntry { _id: string; key: string; - roomId: string; + roomId?: string; // If null, room is expired attemptStartedAt: string; lastAttemptSubmittedAt: string; title: string; diff --git a/frontend/src/presentation/components/RecentAttemptsTable.tsx b/frontend/src/presentation/components/RecentAttemptsTable.tsx index e6900bae18..a74bd3a86e 100644 --- a/frontend/src/presentation/components/RecentAttemptsTable.tsx +++ b/frontend/src/presentation/components/RecentAttemptsTable.tsx @@ -238,14 +238,16 @@ export const RecentAttemptsTable: React.FC = () => { > View Past Code - + {record.roomId && ( + + )} ), },