Skip to content

Commit 9fc3096

Browse files
committed
Move Responsibility of Checking Room Expiry to Question Service
1 parent f0b78f9 commit 9fc3096

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

backend/question-service/controllers/historyController.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ export const getUserHistoryEntries = async (req: any, res: Response) => {
1818
},
1919
});
2020
const historyViewModels = historyEntries.map((entry) => {
21+
const attemptStartDate = new Date(entry.attemptStartedAt);
22+
const timeDiffMs = Date.now() - attemptStartDate.getTime();
23+
24+
const isWithin24Hours = timeDiffMs < 86400000; // 1 Day; Same as ROOM_LIFESPAN in MatchingService. Can be different if desired.
25+
2126
return {
2227
id: entry._id,
2328
key: entry._id,
24-
roomId: entry.roomId,
29+
roomId: isWithin24Hours ? entry.roomId : null,
2530
attemptStartedAt: entry.attemptStartedAt.getTime(),
2631
lastAttemptSubmittedAt: entry.lastAttemptSubmittedAt.getTime(),
2732
title: entry.question.title,

frontend/src/domain/entities/HistoryEntry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface HistoryEntry {
22
_id: string;
33
key: string;
4-
roomId: string;
4+
roomId?: string; // If null, room is expired
55
attemptStartedAt: string;
66
lastAttemptSubmittedAt: string;
77
title: string;

frontend/src/presentation/components/RecentAttemptsTable.tsx

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -208,36 +208,28 @@ export const RecentAttemptsTable: React.FC = () => {
208208
{
209209
title: 'Actions',
210210
key: 'action',
211-
render: (_text, record) => {
212-
const attemptStartDate = new Date(record.attemptStartedAt);
213-
const now = new Date();
214-
const timeDiffMs = now.getTime() - attemptStartDate.getTime();
215-
216-
const isWithin24Hours = timeDiffMs < 86400000; // Should be same as ROOM_LIFESPAN in MatchingService
217-
218-
return (
219-
<Space size="middle" className={styles.actionsButton}>
211+
render: (_text, record) => (
212+
<Space size="middle" className={styles.actionsButton}>
213+
<Button
214+
type="link"
215+
onClick={() => showModal(record.attemptCodes, record.key)}
216+
icon={<EyeOutlined />}
217+
aria-label={`View past code for attempt ${record.key}`}
218+
>
219+
View Past Code
220+
</Button>
221+
{record.roomId && (
220222
<Button
221223
type="link"
222-
onClick={() => showModal(record.attemptCodes, record.key)}
223-
icon={<EyeOutlined />}
224-
aria-label={`View past code for attempt ${record.key}`}
224+
onClick={() => navigate(`/room/${record.roomId}`)}
225+
icon={<TeamOutlined />}
226+
aria-label={`Rejoin room ${record.roomId}`}
225227
>
226-
View Past Code
228+
Rejoin
227229
</Button>
228-
{isWithin24Hours && (
229-
<Button
230-
type="link"
231-
onClick={() => navigate(`/room/${record.roomId}`)}
232-
icon={<TeamOutlined />}
233-
aria-label={`Rejoin room ${record.roomId}`}
234-
>
235-
Rejoin
236-
</Button>
237-
)}
238-
</Space>
239-
);
240-
},
230+
)}
231+
</Space>
232+
),
241233
},
242234
];
243235

0 commit comments

Comments
 (0)