Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reviewController.updateReview = function(req, res, next) {
- if(req.is('application/json')){
- var targetId = req.params.reviewId;
- var productId = req.params.productId;
- for (var i = 0; i < reviewMock.length; i++){
- if (reviewMock[i].productId == productId && reviewMock[i].reviewId == targetId){
- if (req.body.rating){
- reviewMock[i].rating = req.body.rating;
- }
- if (req.body.title){
- reviewMock[i].title = req.body.title;
- }
- if (req.body.body){
- reviewMock[i].body = req.body.body;
- }
- if (req.body.isAnonymous){
- reviewMock[i].isAnonymous = req.body.isAnonymous;
- }
- fs.writeFile('src/mocks/reviews.json', JSON.stringify(reviewMock), function(err){
- if(err){
- next(err);
- }
- return res.sendStatus(202); // 202 Accepted
- });
- } else {
- if(i == reviewMock.length - 1){
- console.log("acess");
- var err = new Error('Not Found');
- err.status = 404;
- next(err);
- }
- }
- }
- } else {
- var err = new Error('Unsupported Media Type')
- err.status = 415;
- next(err);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement