1
1
import { Request , Response } from "express" ;
2
2
import Question from "../models/Question.ts" ;
3
3
import { checkIsExistingQuestion } from "../utils/utils.ts" ;
4
- import { DUPLICATE_QUESTION_RESPONSE_MESSAGE } from "../utils/constants.ts" ;
4
+ import {
5
+ DUPLICATE_QUESTION_RESPONSE_MESSAGE ,
6
+ QN_DESC_EXCEED_CHAR_LIMIT_RESPONSE_MESSAGE ,
7
+ QN_DESC_CHAR_LIMIT ,
8
+ } from "../utils/constants.ts" ;
5
9
6
10
export const createQuestion = async (
7
11
req : Request ,
@@ -18,6 +22,13 @@ export const createQuestion = async (
18
22
return ;
19
23
}
20
24
25
+ if ( description . length > QN_DESC_CHAR_LIMIT ) {
26
+ res . status ( 400 ) . json ( {
27
+ message : QN_DESC_EXCEED_CHAR_LIMIT_RESPONSE_MESSAGE ,
28
+ } ) ;
29
+ return ;
30
+ }
31
+
21
32
const newQuestion = new Question ( {
22
33
title,
23
34
description,
@@ -42,7 +53,7 @@ export const updateQuestion = async (
42
53
) : Promise < void > => {
43
54
try {
44
55
const { id } = req . params ;
45
- const { title } = req . body ;
56
+ const { title, description } = req . body ;
46
57
47
58
const currentQuestion = await Question . findById ( id ) ;
48
59
if ( ! currentQuestion ) {
@@ -58,6 +69,13 @@ export const updateQuestion = async (
58
69
return ;
59
70
}
60
71
72
+ if ( description && description . length > QN_DESC_CHAR_LIMIT ) {
73
+ res . status ( 400 ) . json ( {
74
+ message : QN_DESC_EXCEED_CHAR_LIMIT_RESPONSE_MESSAGE ,
75
+ } ) ;
76
+ return ;
77
+ }
78
+
61
79
const updatedQuestion = await Question . findByIdAndUpdate ( id , req . body , {
62
80
new : true ,
63
81
} ) ;
0 commit comments