From 339c038025b839d6aa1a371da1cecc0f199739af Mon Sep 17 00:00:00 2001 From: thirukumaran05 Date: Sat, 17 Feb 2024 09:12:00 +0530 Subject: [PATCH] Update Validation --- controllers/controller.js | 5 +---- validation/validation.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/controllers/controller.js b/controllers/controller.js index cee7649..1cf0f8a 100644 --- a/controllers/controller.js +++ b/controllers/controller.js @@ -21,7 +21,6 @@ exports.postAge = async (req, res, next) => { try { const doc = await Model.Age.exists({ question: question }); - console.log(doc); if (doc) { const error = new Error("Question Already exists"); error.statusCode = 409; @@ -33,8 +32,6 @@ exports.postAge = async (req, res, next) => { options: options, explanation: explanation, }); - // age = JSON.parse(age); - console.log(age); await age.save(); res.status(201).json({ message: "Question created successfully", @@ -73,7 +70,6 @@ exports.postRandom = async (req, res, next) => { try { const doc = await Model.Random.exists({ question: question }); - console.log(doc); if (doc) { const error = new Error("Question Already exists"); error.statusCode = 409; @@ -511,6 +507,7 @@ exports.updateQuestion = async (req, res, next) => { try { const doc = await model.exists({ question: questionToBeUpdated }); if (!doc) { + console.log(doc) const error = new Error("Question does not exists."); error.statusCode = 404; throw error; diff --git a/validation/validation.js b/validation/validation.js index 0451e08..c9ce21e 100644 --- a/validation/validation.js +++ b/validation/validation.js @@ -3,7 +3,7 @@ const { body, validationResult } = require('express-validator'); const validateQuestion = [ body('question').notEmpty().trim().withMessage('Question cannot be empty'), body('answer').notEmpty().trim().withMessage('Answer cannot be empty, only one answer is allowed'), - body('options', 'Options should be an array with four values, where each value should be in string datatype').notEmpty().isString().trim(), + body('options', 'Options should be an array with four values, where each value should be in string datatype').notEmpty().trim().isArray(), body('explanation').notEmpty().withMessage('Explanation cannot be empty and make sure that explanation is clear').trim() ] ;