Skip to content

Commit f6fcbac

Browse files
committed
matching service unique room for each request
1 parent 3bd25ec commit f6fcbac

File tree

2 files changed

+1
-33
lines changed

2 files changed

+1
-33
lines changed

backend/matching/src/controllers/match-request.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,3 @@ export const matchRequestController = async (req: Request, res: Response) => {
4343

4444
logQueueStatus(logger, redisClient, `Queue Status Before Matching: <PLACEHOLDER>`);
4545
};
46-
47-
export const cancelMatchController = async (req: Request, res: Response) => {
48-
const { requestId, userId } = req.body;
49-
50-
if (!requestId && !userId) {
51-
return res.status(StatusCodes.UNPROCESSABLE_ENTITY).json('Malformed Request');
52-
}
53-
54-
if (!redisClient || !redisClient.isOpen || !redisClient.isReady) {
55-
redisClient = await client.connect();
56-
}
57-
58-
try {
59-
// Remove the user from the match queue
60-
const queueKey = `matchQueue:${requestId || userId}`;
61-
const result = await redisClient.del(queueKey);
62-
63-
if (result > 0) {
64-
logger.info(`Cancelled match request with requestId: ${requestId} or userId: ${userId}`);
65-
res.status(StatusCodes.OK).json({ message: 'Match request cancelled successfully.' });
66-
} else {
67-
logger.warn(`No match request found for requestId: ${requestId} or userId: ${userId}`);
68-
res.status(StatusCodes.NOT_FOUND).json({ error: 'No active match request found to cancel.' });
69-
}
70-
} catch (error) {
71-
logger.error('Error cancelling match request:', error);
72-
res
73-
.status(StatusCodes.INTERNAL_SERVER_ERROR)
74-
.json({ error: 'Failed to cancel match request.' });
75-
}
76-
};
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { matchRequestController } from '@/controllers/match-request';
2-
import { cancelMatchController } from '@/controllers/match-request';
2+
33
import { Router } from 'express';
44

55
const route = Router();
66

77
route.post('/request', matchRequestController);
8-
route.post('/cancel', cancelMatchController);
98

109
export default route;

0 commit comments

Comments
 (0)