Skip to content

Instantly share code, notes, and snippets.

@simonrenoult
Created May 16, 2018 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonrenoult/e8eb0934669eb0aadcd83b1ea6b91a65 to your computer and use it in GitHub Desktop.
Save simonrenoult/e8eb0934669eb0aadcd83b1ea6b91a65 to your computer and use it in GitHub Desktop.
const productSchema = Joi.object().keys({
name: Joi.required(),
price: Joi.required(),
weight: Joi.required()
});
// …
app.post("/products", async (req, res) => {
const { error } = Joi.validate(req.body, productSchema, { abortEarly: false });
if (error) {
const errorMessage = error.details.map(({ message, context }) => { message, context });
return res.status(400).send({ data: errorMessage });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment