Skip to content

Commit

Permalink
feat: Cancel session --> cancel by user, not session id
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongbeom-Kim committed Oct 19, 2024
1 parent 33f813d commit a031863
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ export const cancelSession = async (
res: Response
): Promise<void> => {
try {
const { sessionId } = req.body;
const { userId } = req.body;

// Cancel the timeout and remove session from Redis
await redis.delSession(sessionId);
await redis.delSessionByUser(userId);

res.status(200).json({ message: "Session timeout cancelled." });
} catch (error) {
Expand Down
8 changes: 8 additions & 0 deletions peerprep/backend/matching-service/src/utils/redisUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ export const delSession = async (sessionId: string): Promise<void> => {
}
};

export const delSessionByUser = async (userId: string): Promise<void> => {
const session = await findSessionByUser(userId);
if (!session) {
throw new Error("User is not in a session");
}
await delSession(session.sessionId);
}

export const findSession = async (
sessionId: string
): Promise<Session | null> => {
Expand Down

0 comments on commit a031863

Please sign in to comment.