@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
} ) ;
10
10
} ;
11
11
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
12
- exports . handleAddQuestion = exports . handleDeleteQuestion = exports . handleGetQuestions = void 0 ;
12
+ exports . handleAddQuestion = exports . handleUpdateQuestion = exports . handleDeleteQuestion = exports . handleGetQuestions = void 0 ;
13
13
const question_service_1 = require ( "./question.service" ) ;
14
14
const firestore_1 = require ( "firebase/firestore" ) ;
15
15
function handleGetQuestions ( req , res ) {
@@ -63,8 +63,9 @@ function handleDeleteQuestion(req, res) {
63
63
return __awaiter ( this , void 0 , void 0 , function * ( ) {
64
64
const questionId = req . params . questionId ;
65
65
try {
66
- const docRef = ( 0 , firestore_1 . doc ) ( question_service_1 . db , "questions" , questionId ) ;
67
- const result = yield ( 0 , firestore_1 . deleteDoc ) ( docRef ) ;
66
+ console . log ( `deleting question with id ${ questionId } ` ) ;
67
+ yield ( 0 , question_service_1 . deleteQuestion ) ( questionId ) ;
68
+ res . status ( 200 ) . send ( `question with id "${ questionId } " deleted` ) ;
68
69
}
69
70
catch ( err ) {
70
71
console . log ( `error when deleting question with id ${ questionId } ` + err ) ;
@@ -73,23 +74,45 @@ function handleDeleteQuestion(req, res) {
73
74
} ) ;
74
75
}
75
76
exports . handleDeleteQuestion = handleDeleteQuestion ;
76
- function handleAddQuestion ( req , res ) {
77
+ function handleUpdateQuestion ( req , res ) {
77
78
return __awaiter ( this , void 0 , void 0 , function * ( ) {
79
+ const questionId = req . params . questionId ;
78
80
try {
79
- const { qtitle, qtags, qcategories, qconstraints, qdifficulty, qdescription, qexamples, } = req . body ;
80
- const docRef = yield ( 0 , firestore_1 . addDoc ) ( ( 0 , firestore_1 . collection ) ( question_service_1 . db , "questions" ) , {
81
- title : qtitle ,
82
- tags : qtags ,
83
- categories : qcategories ,
84
- constraints : qconstraints ,
85
- difficulty : qdifficulty ,
86
- description : qdescription ,
81
+ const { title, tags, categories, constraints, difficulty, description, examples, } = req . body ;
82
+ console . log ( `updating question ${ questionId } : ${ title } ` ) ;
83
+ const question = yield ( 0 , question_service_1 . updateQuestion ) ( questionId , {
84
+ title : title ,
85
+ tags : tags ,
86
+ categories : categories ,
87
+ constraints : constraints ,
88
+ difficulty : difficulty ,
89
+ description : description ,
90
+ examples : examples ,
87
91
} ) ;
88
- const exampleRef = ( 0 , firestore_1 . collection ) ( docRef , "examples" ) ;
89
- qexamples . map ( ( e ) => {
90
- const add = ( 0 , firestore_1 . addDoc ) ( exampleRef , e ) ;
92
+ res . status ( 200 ) . send ( question ) ;
93
+ }
94
+ catch ( err ) {
95
+ console . log ( err ) ;
96
+ res . status ( 500 ) . send ( err ) ;
97
+ }
98
+ } ) ;
99
+ }
100
+ exports . handleUpdateQuestion = handleUpdateQuestion ;
101
+ function handleAddQuestion ( req , res ) {
102
+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
103
+ try {
104
+ const { title, tags, categories, constraints, difficulty, description, examples, } = req . body ;
105
+ console . log ( `adding question ${ title } ` ) ;
106
+ const question = yield ( 0 , question_service_1 . addQuestion ) ( {
107
+ title : title ,
108
+ tags : tags ,
109
+ categories : categories ,
110
+ constraints : constraints ,
111
+ difficulty : difficulty ,
112
+ description : description ,
113
+ examples : examples ,
91
114
} ) ;
92
- // const addExample = setDoc(exampleRef, qexamples)
115
+ res . status ( 200 ) . send ( question ) ;
93
116
}
94
117
catch ( err ) {
95
118
console . log ( err ) ;
0 commit comments