Skip to content

Commit bbbb481

Browse files
committed
Add event response
1 parent fd9879c commit bbbb481

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

backend/gateway-service/src/modules/match/match.controller.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,39 @@ export class MatchGateway implements OnGatewayInit {
204204
// Remove match-related data
205205
this.matchParticipants.delete(matchId);
206206
this.matchConfirmations.delete(matchId);
207-
client.emit(MATCH_DECLINED, { message: 'You have declined the match.' });
207+
client.emit(MATCH_DECLINED, {
208+
message: 'You have declined the match.',
209+
isDecliningUser: true,
210+
});
208211
}
209212

210213
// Notify both users when they are matched
211-
notifyUsersWithMatch(matchedUsers: string[]) {
214+
async notifyUsersWithMatch(matchedUsers: string[]) {
212215
const [user1, user2] = matchedUsers;
213216
const user1SocketId = this.getUserSocketId(user1);
214217
const user2SocketId = this.getUserSocketId(user2);
215218

219+
const user1Details = await firstValueFrom(
220+
this.userClient.send({ cmd: 'get-user-by-id' }, user1),
221+
);
222+
223+
const user2Details = await firstValueFrom(
224+
this.userClient.send({ cmd: 'get-user-by-id' }, user2),
225+
);
226+
216227
if (user1SocketId && user2SocketId) {
217228
const matchId = this.generateMatchId();
218229
this.server.to(user1SocketId).emit(MATCH_FOUND, {
219230
message: `You have found a match`,
220-
matchUserId: user2,
221231
matchId,
232+
matchUserId: user2,
233+
matchUsername: user2Details.username,
222234
});
223235
this.server.to(user2SocketId).emit(MATCH_FOUND, {
224236
message: `You have found a match`,
225-
matchUserId: user1,
226237
matchId,
238+
matchUserId: user1,
239+
matchUsername: user1Details.username,
227240
});
228241

229242
// Store participants for this matchId
@@ -260,6 +273,7 @@ export class MatchGateway implements OnGatewayInit {
260273
if (socketId) {
261274
this.server.to(socketId).emit(MATCH_DECLINED, {
262275
message: 'The other user has declined the match.',
276+
isDecliningUser: false,
263277
});
264278
}
265279
}

0 commit comments

Comments
 (0)