Skip to content

Commit 23e41d4

Browse files
committed
Fix Room Schema Mapping
1 parent acc79b8 commit 23e41d4

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

backend/matching-service/models/RoomSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface Room extends mongoose.Document {
1212

1313

1414
const roomSchema: Schema<Room> = new mongoose.Schema<Room>({
15-
participants: [{ userId: String }],
15+
participants: [{ type: String }],
1616
category: { type: String, default: 'Any' },
1717
difficulty: { type: String, default: 'Any' },
1818
roomId: { type: String, required: true },

backend/matching-service/workers/matchWorker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ async function handleMatch(user1: any, user2: any) {
244244
matchId: savedEvent._id.toString(),
245245
};
246246

247-
await producer.send({
247+
await producer.send({
248248
topic: MATCH_TOPIC,
249249
messages: [
250250
{
@@ -395,18 +395,23 @@ export async function emitMatchEvent(matchId: string) {
395395
}
396396

397397
const roomObject = JSON.parse(data);
398+
console.log(roomObject);
398399

399400
if (roomObject.questionId && roomObject.roomId) {
400401
const newRoom = new Room({
401402
participants: [
402-
{ userId: roomObject.user1.userId },
403-
{ userId: roomObject.user2.userId },
403+
JSON.parse(roomObject.user1).userId,
404+
JSON.parse(roomObject.user2).userId,
404405
],
405406
category: roomObject.category,
406407
difficulty: roomObject.difficulty,
407408
roomId: roomObject.roomId,
408409
questionId: roomObject.questionId,
409410
});
411+
console.log(newRoom);
412+
console.log(
413+
JSON.parse(roomObject.user1).userId,
414+
JSON.parse(roomObject.user2).userId);
410415

411416
await newRoom.save();
412417

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface Room {
22
roomId: string;
33
attemptStartedAt: string;
4-
userIdOne: { _id: string };
5-
userIdTwo: { _id: string };
4+
userIdOne: string;
5+
userIdTwo: string;
66
questionId: string;
77
}

frontend/src/domain/usecases/HistoryUseCases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class HistoryUseCases {
2525
|| !attemptStartedAt || attemptStartedAt.trim() === ""
2626
|| !attemptCompletedAt || attemptCompletedAt.trim() === ""
2727
|| !collaboratorId || collaboratorId.trim() === "") {
28-
throw new Error("Missing Attempt Details");
28+
throw new Error(`Missing Attempt Details, ${questionId} ${roomId} ${attemptStartedAt} ${attemptCompletedAt} ${collaboratorId} ${attemptCode}`);
2929
}
3030
await this.historyRepository.createOrUpdateUserHistory(questionId, roomId, attemptStartedAt, attemptCompletedAt, collaboratorId, attemptCode, true);
3131
}
@@ -42,7 +42,7 @@ export class HistoryUseCases {
4242
|| !attemptStartedAt || attemptStartedAt.trim() === ""
4343
|| !attemptCompletedAt || attemptCompletedAt.trim() === ""
4444
|| !collaboratorId || collaboratorId.trim() === "") {
45-
throw new Error("Missing Attempt Details");
45+
throw new Error(`Missing Attempt Details, ${questionId} ${roomId} ${attemptStartedAt} ${attemptCompletedAt} ${collaboratorId} ${attemptCode}`);
4646
}
4747
await this.historyRepository.createOrUpdateUserHistory(questionId, roomId, attemptStartedAt, attemptCompletedAt, collaboratorId, attemptCode, false);
4848
}

frontend/src/presentation/pages/room/CollaborationRoomPage.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ const CollaborationRoomPage: React.FC = () => {
4444
setRoom({
4545
roomId: roomId,
4646
attemptStartedAt: attemptStartedAt,
47-
userIdOne: { _id: user!._id },
48-
userIdTwo: { _id: matchUserId },
47+
userIdOne: user!._id,
48+
userIdTwo: matchUserId,
4949
questionId: questionId
5050
});
5151
} else {
5252
if (!urlRoomId) return;
5353
// Fetch room details from API
5454
const fetchedRoom = await roomUseCases.getRoomDetails(urlRoomId);
55+
console.log("Fetched Room", fetchedRoom)
5556
// Ensure the current user is userIdOne
56-
if (fetchedRoom.userIdOne._id !== user?._id) {
57+
if (fetchedRoom.userIdOne !== user!._id) {
5758
const temp = fetchedRoom.userIdOne;
5859
fetchedRoom.userIdOne = fetchedRoom.userIdTwo;
5960
fetchedRoom.userIdTwo = temp;
@@ -132,14 +133,16 @@ const CollaborationRoomPage: React.FC = () => {
132133
<div className={styles.verticalSeparator} {...verticalSeparatorProps} />
133134

134135
<div className={styles.editorAndOutputContainer}>
135-
<div className={styles.editorContainer}>
136-
<CodeEditor
137-
questionId={room.questionId}
138-
roomId={room.roomId}
139-
attemptStartedAt={new Date(room.attemptStartedAt)}
140-
collaboratorId={room.userIdTwo?._id}
141-
/>
142-
</div>
136+
{room.questionId && room.roomId && room.attemptStartedAt && room.userIdTwo &&
137+
<div className={styles.editorContainer}>
138+
<CodeEditor
139+
questionId={room.questionId}
140+
roomId={room.roomId}
141+
attemptStartedAt={new Date(room.attemptStartedAt)}
142+
collaboratorId={room.userIdTwo}
143+
/>
144+
</div>
145+
}
143146

144147
<div className={styles.horizontalSeparator} {...horizontalSeparatorProps} />
145148

0 commit comments

Comments
 (0)