17 lines
396 B
JavaScript
17 lines
396 B
JavaScript
|
const Joi = require("joi");
|
||
|
|
||
|
const validation = Joi.object({
|
||
|
comment: Joi.string().required(),
|
||
|
blogId: Joi.string().required()
|
||
|
});
|
||
|
|
||
|
function commentValidater(req, res, next) {
|
||
|
const { error } = validation.validate(req.body);
|
||
|
if (error) {
|
||
|
res.status(406).json({ msg: "Comment is not valid", details: error.details });
|
||
|
} else {
|
||
|
next();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = commentValidater;
|