Guest User

Untitled

a guest
May 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. app.post("/products", async (req, res) => {
  2. const { error } = Joi.validate(req.body, productSchema, { abortEarly: false });
  3.  
  4. if (error) {
  5. const errorMessage = error.details.map(({ message, context }) =>
  6. Object.assign({ message, context })
  7. );
  8. return res.status(400).send({ data: errorMessage });
  9. }
  10.  
  11. const product = await Product.create(req.body);
  12.  
  13. res.status(201).send();
  14. });
Add Comment
Please, Sign In to add comment