SHARE
TWEET

Untitled

a guest Mar 19th, 2019 214 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.put("/update/:id", async (req, res) => {
  2.   try {
  3.     const { id } = req.params;
  4.     const query = { _id: id, type: "partner" };
  5.     const user = await User.findOne(query);
  6.     const isValidated = validator.updateValidation(req.body);
  7.     if (!user)
  8.       // Bad request if not found
  9.       return res.status(400).send({ error: "id not found" });
  10.     if (isValidated.error) {
  11.       return res
  12.         .status(400)
  13.         .send({ error: isValidated.error.details[0].message });
  14.     }
  15.     const { name, email, ...userData } = req.body;
  16.     console.log(user, user.userData);
  17.     userData.feedback = user.userData.feedback;
  18.     await User.updateOne(query, { name, email, userData });
  19.     return res.sendStatus(200);
  20.   } catch (error) {
  21.     console.log(error);
  22.   }
  23. });
  24.      
  25. { _id: 5c9146e6148d9398889993e2,
  26.   type: 'partner',
  27.   name: 'youssef',
  28.   email: 'firstMongo@hotmail.com',
  29.   userData:
  30.    { address: 'hi there',
  31.      fax: '123124124',
  32.      phone: '023124124',
  33.      partners: null,
  34.      members: null,
  35.      fieldOfWork: null,
  36.      projects: null,
  37.      feedback: [] },
  38.   password: 'test',
  39.   __v: 0 } undefined
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top