Created
May 18, 2018 14:48
-
-
Save simonrenoult/56698a8cde7e609470e295b1a32aa237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.set("Location", `/products/${product.id}`); | |
res.status(201).send(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment