Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.put("/update/:id", async (req, res) => {
- try {
- const { id } = req.params;
- const query = { _id: id, type: "partner" };
- const user = await User.findOne(query);
- const isValidated = validator.updateValidation(req.body);
- if (!user)
- // Bad request if not found
- return res.status(400).send({ error: "id not found" });
- if (isValidated.error) {
- return res
- .status(400)
- .send({ error: isValidated.error.details[0].message });
- }
- const { name, email, ...userData } = req.body;
- console.log(user, user.userData);
- userData.feedback = user.userData.feedback;
- await User.updateOne(query, { name, email, userData });
- return res.sendStatus(200);
- } catch (error) {
- console.log(error);
- }
- });
- { _id: 5c9146e6148d9398889993e2,
- type: 'partner',
- name: 'youssef',
- email: 'firstMongo@hotmail.com',
- userData:
- { address: 'hi there',
- fax: '123124124',
- phone: '023124124',
- partners: null,
- members: null,
- fieldOfWork: null,
- projects: null,
- feedback: [] },
- password: 'test',
- __v: 0 } undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement