Skip to content

Commit

Permalink
Update Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiru-kumaran-R committed Feb 17, 2024
1 parent 913b65b commit 339c038
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
] ;

Expand Down

1 comment on commit 339c038

@vercel
Copy link

@vercel vercel bot commented on 339c038 Feb 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.