Skip to content

Commit 5ffa892

Browse files
committed
Fix minor bugs
1 parent 95c4072 commit 5ffa892

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

backend/question/src/routes/questionRoutes.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ router.post("/all", async (req: Request, res: Response) => {
6565
const { title, complexity, category } = req.body;
6666

6767
const query: any = { deleted: false };
68-
if (title !== "") query.title = { $regex: title, $options: "i" };
68+
if (title && title !== "") query.title = { $regex: title, $options: "i" };
6969
if (complexity && complexity.length > 0)
7070
query.complexity = { $in: complexity };
7171
if (category && category.length > 0) query.category = { $in: category };
@@ -228,10 +228,6 @@ router.post(
228228
);
229229
return res.json(updatedQuestion);
230230
} catch (error) {
231-
//to catch pre-middleware defined error
232-
if (error instanceof Error) {
233-
return res.status(404).json(error.message);
234-
}
235231
return res.status(500).send("Internal server error");
236232
}
237233
}

backend/question/src/routes/validators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export const idValidators = [check("id").isInt({ min: 1 })];
2929
export const pickQuestionValidators = [
3030
check("complexity").custom((complexity) => {
3131
if (!Array.isArray(complexity) || complexity.length === 0) {
32-
throw new Error("Category must be a non-empty array");
32+
throw new Error("Complexity must be a non-empty array");
3333
}
3434
if (
3535
!complexity.every(
3636
(element) => typeof element === "string" && element.trim().length > 0
3737
)
3838
) {
39-
throw new Error("Category must contain only non-empty strings");
39+
throw new Error("Complexity must contain only non-empty strings");
4040
}
4141
return true;
4242
}),

0 commit comments

Comments
 (0)