1
1
import { Request , Response } from "express" ;
2
2
import Question , { IQuestion } from "../models/Question.ts" ;
3
- import { checkIsExistingQuestion , sortAlphabetically } from "../utils/utils.ts" ;
3
+ import { checkIsExistingQuestion } from "../utils/utils.ts" ;
4
4
import {
5
5
DUPLICATE_QUESTION_MESSAGE ,
6
6
QN_DESC_EXCEED_CHAR_LIMIT_MESSAGE ,
@@ -13,8 +13,6 @@ import {
13
13
PAGE_LIMIT_REQUIRED_MESSAGE ,
14
14
PAGE_LIMIT_INCORRECT_FORMAT_MESSAGE ,
15
15
CATEGORIES_RETRIEVED_MESSAGE ,
16
- MONGO_OBJ_ID_FORMAT ,
17
- MONGO_OBJ_ID_MALFORMED_MESSAGE ,
18
16
} from "../utils/constants.ts" ;
19
17
20
18
import { upload } from "../../config/multer" ;
@@ -80,7 +78,6 @@ export const createImageLink = async (
80
78
81
79
const uploadPromises = files . map ( ( file ) => uploadFileToFirebase ( file ) ) ;
82
80
const imageUrls = await Promise . all ( uploadPromises ) ;
83
- console . log ( imageUrls ) ;
84
81
res
85
82
. status ( 200 )
86
83
. json ( { message : "Images uploaded successfully" , imageUrls } ) ;
@@ -98,13 +95,7 @@ export const updateQuestion = async (
98
95
const { id } = req . params ;
99
96
const { title, description } = req . body ;
100
97
101
- if ( ! id . match ( MONGO_OBJ_ID_FORMAT ) ) {
102
- res . status ( 400 ) . json ( { message : MONGO_OBJ_ID_MALFORMED_MESSAGE } ) ;
103
- return ;
104
- }
105
-
106
98
const currentQuestion = await Question . findById ( id ) ;
107
-
108
99
if ( ! currentQuestion ) {
109
100
res . status ( 404 ) . json ( { message : QN_NOT_FOUND_MESSAGE } ) ;
110
101
return ;
@@ -212,12 +203,7 @@ export const readQuestionsList = async (
212
203
res . status ( 200 ) . json ( {
213
204
message : QN_RETRIEVED_MESSAGE ,
214
205
questionCount : filteredQuestionCount ,
215
- questions : filteredQuestions
216
- . map ( formatQuestionResponse )
217
- . map ( ( question ) => ( {
218
- ...question ,
219
- categories : sortAlphabetically ( question . categories ) ,
220
- } ) ) ,
206
+ questions : filteredQuestions . map ( formatQuestionResponse ) ,
221
207
} ) ;
222
208
} catch ( error ) {
223
209
res . status ( 500 ) . json ( { message : SERVER_ERROR_MESSAGE , error } ) ;
@@ -255,7 +241,7 @@ export const readCategories = async (
255
241
256
242
res . status ( 200 ) . json ( {
257
243
message : CATEGORIES_RETRIEVED_MESSAGE ,
258
- categories : sortAlphabetically ( uniqueCats ) ,
244
+ categories : uniqueCats ,
259
245
} ) ;
260
246
} catch ( error ) {
261
247
res . status ( 500 ) . json ( { message : SERVER_ERROR_MESSAGE , error } ) ;
0 commit comments