Skip to content

Commit a8d0d74

Browse files
authored
Merge pull request #118 from CS3219-AY2425S1/fix-incorrect-room-schema
Fix incorrect room schema
2 parents acc79b8 + 5421e89 commit a8d0d74

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,14 @@ export async function emitMatchEvent(matchId: string) {
399399
if (roomObject.questionId && roomObject.roomId) {
400400
const newRoom = new Room({
401401
participants: [
402-
{ userId: roomObject.user1.userId },
403-
{ userId: roomObject.user2.userId },
402+
JSON.parse(roomObject.user1).userId,
403+
JSON.parse(roomObject.user2).userId,
404404
],
405405
category: roomObject.category,
406406
difficulty: roomObject.difficulty,
407407
roomId: roomObject.roomId,
408408
questionId: roomObject.questionId,
409409
});
410-
411410
await newRoom.save();
412411

413412
await redisClient.xAdd("match_events", "*", { data });
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/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)