File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
backend/question/src/services/post Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -26,14 +26,17 @@ export const createQuestionService = async (payload: ICreateQuestionPayload) =>
26
26
27
27
export const updateQuestionService = async ( payload : IUpdateQuestionPayload ) => {
28
28
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
+
29
37
const [ updatedQuestion ] = await db
30
38
. 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 )
37
40
. where ( eq ( questions . id , Number ( payload . id ) ) )
38
41
. returning ( ) ;
39
42
You can’t perform that action at this time.
0 commit comments