Skip to content

Commit 1f1bb99

Browse files
authored
Merge branch 'main' into anun/fix1
2 parents 9a98c9e + 7225ddb commit 1f1bb99

File tree

1 file changed

+9
-6
lines changed
  • backend/question/src/services/post

1 file changed

+9
-6
lines changed

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)