Skip to content

Commit 4ff8f4a

Browse files
authored
Merge pull request #112 from CS3219-AY2425S1/add-room-expiry
Add Room Expiry
2 parents 3689380 + fdae437 commit 4ff8f4a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

backend/matching-service/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ CLEANUP_INTERVAL=75000
2020

2121
JWT_ACCESS_TOKEN_SECRET=<your-jwt-accecss-token>
2222

23+
# Lifespan of a room (1 day in milliseconds)
24+
ROOM_LIFESPAN=86400000
25+
2326
# Copy root .env
2427
# If using mongoDB containerization, set to true. Else set to false (i.e local testing)
2528
DB_REQUIRE_AUTH=true

backend/matching-service/controllers/roomController.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import roomModel from "../models/RoomSchema";
22
import { Request, Response, NextFunction } from "express";
33

4+
const ROOM_LIFESPAN = parseInt(process.env.ROOM_LIFESPAN || "86400000"); // 86400000ms = 1 day
5+
46
export async function getRoomDetails(
57
request: Request,
68
response: Response,
@@ -13,6 +15,9 @@ export async function getRoomDetails(
1315
if (!room) {
1416
throw new Error("Room not found");
1517
}
18+
if (Date.now() - room.createdAt.getTime() > ROOM_LIFESPAN) {
19+
throw new Error("Room has expired");
20+
}
1621
response.status(200).json({
1722
roomId,
1823
attemptStartedAt: room.createdAt.getTime(),

0 commit comments

Comments
 (0)