<commit_before>'use strict';

const Router = require('express').Router;
const jsonParser = require('body-parser').json();
// const createError = require('http-errors');
const debug = require('debug')('ways2go*:review-router');

const Review = require('../model/review.js');
const Profile = require('../model/profile.js');
const bearerAuth = require('../lib/bearer-auth-middleware.js');

const reviewRouter = module.exports = Router();

reviewRouter.post('/api/wayerz/:wayerzID/review', bearerAuth, jsonParser, function(req, res, next) {
  debug('POST: /api/wayerz/:wayerzID/review');

  req.body.userID = req.user._id;

  Profile.findByIdAndAddReview(req.params.wayerzID, req.body)
  .then( review => res.json(review))
  .catch(next);
});

reviewRouter.put('/api/review/:id', bearerAuth, jsonParser, function(req, res, next) {
  debug('PUT: /api/review/:id');

  Review.findByIdAndUpdate(req.params.id, req.body, { new: true})
  .then( review => {
    review.rating = req.body.rating;
    review.comment = req.body.comment;
    return review.save();
  })
  .then( review => res.json(review))
  .catch(next);
});

reviewRouter.get('/api/wayerz/:wayerzID/review', bearerAuth, function(req, res, next) {
  debug('GET: /api/wayerz/:wayerzID/review');

  Profile.findById(req.params.wayerzID)
  .populate('reviews')
  .then( profile => {
    res.json(profile.reviews);
  })
  .catch(next);
});

reviewRouter.delete('/api/review/:id', bearerAuth, function(req, res, next) {
  debug('DELETE: /api/review/:id');

  Review.findByIdAndRemove(req.params._id)
  .then( () => res.status(204).send())
  .catch(next);
});

reviewRouter.get('/api/wayerz/:wayerzID/review', bearerAuth, function(req, res, next) {
  debug('GET: /api/wayerz/:wayerzID/review');

  Review.findById(req.params.id)
  .then( review => {
    res.json(review);
  })
  .catch(next);
});<commit_msg>fixed delete in router<commit_after>'use strict';

const Router = require('express').Router;
const jsonParser = require('body-parser').json();
// const createError = require('http-errors');
const debug = require('debug')('ways2go*:review-router');

const Review = require('../model/review.js');
const Profile = require('../model/profile.js');
const bearerAuth = require('../lib/bearer-auth-middleware.js');

const reviewRouter = module.exports = Router();

reviewRouter.post('/api/wayerz/:wayerzID/review', bearerAuth, jsonParser, function(req, res, next) {
  debug('POST: /api/wayerz/:wayerzID/review');

  req.body.userID = req.user._id;

  Profile.findByIdAndAddReview(req.params.wayerzID, req.body)
  .then( review => res.json(review))
  .catch(next);
});

reviewRouter.put('/api/review/:id', bearerAuth, jsonParser, function(req, res, next) {
  debug('PUT: /api/review/:id');

  Review.findByIdAndUpdate(req.params.id, req.body, { new: true})
  .then( review => {
    review.rating = req.body.rating;
    review.comment = req.body.comment;
    return review.save();
  })
  .then( review => res.json(review))
  .catch(next);
});

reviewRouter.get('/api/wayerz/:wayerzID/review', bearerAuth, function(req, res, next) {
  debug('GET: /api/wayerz/:wayerzID/review');

  Profile.findById(req.params.wayerzID)
  .populate('reviews')
  .then( profile => {
    res.json(profile.reviews);
  })
  .catch(next);
});

reviewRouter.delete('/api/review/:id', bearerAuth, function(req, res, next) {
  debug('DELETE: /api/review/:id');

  Review.findByIdAndRemove(req.params._id)
  .then( () => res.status(204).send())
  .catch(next);
});
{'fraction_non_alphanumeric': 0.1987363584147042, 'fraction_numerical': 0.0022975301550832855, 'mean_word_length': 4.511075949367089, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6163785', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1233, 'n_words': 197}