Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "_id": "5b4cebf353dc12159b769d9c",
- "name": "Profile_A",
- "handle": "profile_a",
- "date": "2018-07-16T19:03:15.341Z",
- "__v": 0
- },
- {
- "_id": "5b4d3957a5adce2572865b98",
- "name": "Profile_B",
- "handle": "profile_b",
- "date": "2018-07-17T00:33:27.266Z",
- "__v": 0
- },
- {
- "_id": "5b4d507bb71d9727ce8a5504",
- "name": "Profile_C",
- "handle": "profile_c",
- "date": "2018-07-17T02:12:11.204Z",
- "__v": 0
- }
- ]
- // @POST api/profile/handle/:handle
- // @desc Update Profile By Handle
- router.post('/handle/:handle', (req, res) => {
- const profileFields = {};
- const { errorsObj, isValid } = validateProfile(req.body);
- const trimHandle = n => n.toLowerCase().replace(/s/g, '_');
- // Check Validation
- if (!isValid) {
- return res.status(404).json(errorsObj);
- }
- ProfileModel.findOne({ handle: req.params.handle })
- .then(profile => {
- if (!profile) {
- errorsObj.noprofile = 'There is no profile';
- res.status(404).json(errorsObj);
- }
- if (req.body.name) profileFields.name = req.body.name;
- if (req.body.name) clientProfileFields.handle = trimHandle(req.body.name)
- // UPDATE
- ProfileModel.findOneAndUpdate(
- { name: profileFields.name },
- { $set: profileFields },
- { new: true }
- ).then(profile => res.json(profile));
- })
- .catch(err => res.status(404).json(err));
Add Comment
Please, Sign In to add comment