Skip to content

Instantly share code, notes, and snippets.

@simonrenoult
Created May 18, 2018 14:46
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/e7b311ee8ec22b3d050f7b33a28f1068 to your computer and use it in GitHub Desktop.
Save simonrenoult/e7b311ee8ec22b3d050f7b33a28f1068 to your computer and use it in GitHub Desktop.
app.post("/products", async (req, res) => {
const { error } = Joi.validate(req.body, productSchema, { abortEarly: false });
if (error) {
const errorMessage = error.details.map(({ message, context }) =>
Object.assign({ message, context })
);
return res.status(400).send({ data: errorMessage });
}
const product = await Product.create(req.body);
res.status(201).send();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment