From e5a32f01fd0d3dfdacac7f0d30af259b2c38b8fc Mon Sep 17 00:00:00 2001 From: KhoonSun47 Date: Sat, 28 Sep 2024 16:20:51 +0800 Subject: [PATCH] Update questionController.ts --- services/question/src/controllers/questionController.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/question/src/controllers/questionController.ts b/services/question/src/controllers/questionController.ts index 033a8a02a5..df804ea397 100644 --- a/services/question/src/controllers/questionController.ts +++ b/services/question/src/controllers/questionController.ts @@ -201,7 +201,12 @@ export const updateQuestion = async (req: Request, res: Response) => { try { const existingQuestion = await Question.findOne({ - $or: [{ title: updates.title }, { description: updates.description }], + $and: [ + { + $or: [{ title: updates.title }, { description: updates.description }], + }, + { id: { $ne: parseInt(id, 10) } }, + ], }).collation({ locale: 'en', strength: 2 }); if (existingQuestion) { return handleBadRequest(res, 'A question with the same title or description already exists.');