Skip to content

Commit 8854d6c

Browse files
authored
Merge branch 'main' into D4-ui-fixes
2 parents b3f9813 + 5bb9fcf commit 8854d6c

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

backend/matching/src/services/get-match-items.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from '@/lib/utils';
12
import type { IMatchItemsResponse, IMatchType } from '@/types';
23

34
import { createRoom } from './collab';
@@ -16,12 +17,18 @@ export async function getMatchItems(
1617
throw new Error('Both user IDs are required');
1718
}
1819

19-
const [attemptedQuestions1, attemptedQuestions2] = await Promise.all([
20-
fetchAttemptedQuestions(userId1),
21-
fetchAttemptedQuestions(userId2),
22-
]);
20+
let allAttemptedQuestions: number[] = [];
21+
22+
try {
23+
const [attemptedQuestions1, attemptedQuestions2] = await Promise.all([
24+
fetchAttemptedQuestions(userId1),
25+
fetchAttemptedQuestions(userId2),
26+
]);
27+
allAttemptedQuestions = [...new Set([...attemptedQuestions1, ...attemptedQuestions2])];
28+
} catch (error) {
29+
logger.error('Error in getMatchItems: Failed to fetch attempted questions', error);
30+
}
2331

24-
const allAttemptedQuestions = [...new Set([...attemptedQuestions1, ...attemptedQuestions2])];
2532
const topics = topic?.split('|') ?? [];
2633
const payload = {
2734
attemptedQuestions: allAttemptedQuestions,
@@ -35,16 +42,21 @@ export async function getMatchItems(
3542
// Get a random question
3643
const question = await getRandomQuestion(payload);
3744

45+
if (!question) {
46+
logger.info('No matching question found');
47+
return undefined;
48+
}
49+
3850
const roomId = await createRoom(userId1, userId2, question.id.toString());
3951

40-
console.log('Successfully got match items');
52+
logger.info('Successfully got match items');
4153
return {
4254
roomId,
4355
questionId: question.id,
4456
// question,
4557
};
4658
} catch (error) {
47-
console.error('Error in getMatchItems:', error);
59+
logger.error('Error in getMatchItems:', error);
4860
return undefined;
4961
}
5062
}

backend/question/src/services/post/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ export const createQuestionService = async (payload: ICreateQuestionPayload) =>
2626

2727
export const updateQuestionService = async (payload: IUpdateQuestionPayload) => {
2828
try {
29+
const updateSet: Partial<typeof questions.$inferInsert> = {};
30+
31+
if (payload.title !== undefined) updateSet.title = payload.title;
32+
if (payload.description !== undefined) updateSet.description = payload.description;
33+
if (payload.difficulty !== undefined) updateSet.difficulty = payload.difficulty;
34+
if (payload.topics !== undefined && Array.isArray(payload.topics))
35+
updateSet.topic = payload.topics.map(String);
36+
2937
const [updatedQuestion] = await db
3038
.update(questions)
31-
.set({
32-
title: payload.title,
33-
description: payload.description,
34-
difficulty: payload.difficulty,
35-
topic: payload.topics.map(String),
36-
})
39+
.set(updateSet)
3740
.where(eq(questions.id, Number(payload.id)))
3841
.returning();
3942

0 commit comments

Comments
 (0)