Created
January 7, 2018 03:19
-
-
Save mrhm-dev/10db56b6d73b7b65a530dae6e6a3dd6e to your computer and use it in GitHub Desktop.
Using a different approach to patch method in this code.
value should be pass with request as below
[ {obj}, {obj}
]
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
router.put('/:newsId', (req, res, next) => { | |
const _id = req.params.newsId; | |
const updateOptions = {}; | |
for(let ops of req.body) { | |
updateOptions[ops.propName] = ops.value; | |
} | |
// Called Update Method from News Model | |
News.update({_id}, {$set: updateOptions}) | |
.exec() | |
.then(result => { | |
res.status(200).json({ | |
message: 'News Updated', | |
request: { | |
type: 'GET', | |
url: `${URL}/${_id}` | |
} | |
}); | |
}) | |
.catch(err => { | |
console.log(err); | |
res.status(500).json({ | |
error: err | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment