<commit_before>var express = require('express');
var router = express.Router();
var transactions = require('../../controllers/transactions');
var moment = require('moment');

router.get('/', render);
router.get('/date/:year/:month', render);
router.get('/date/:year/:month/:category', render);

router.get('/categories', categories);
router.get('/categories/:start_date/:end_date', categories);
router.get('/import', function(req, res, next) {
  res.render('import', { viewName: 'import' });
});

module.exports = router;

function render(req, res, next) {
  var year = req.params.year;
  var month = req.params.month;
  var category = req.params.category;

  transactions.view({year, month}, category)
    .then(function(view) {
      res.render('index', view);
    }).catch(next);
}

function categories(req, res, next) {
  var start = req.params.start_date || new Date();
  var end = req.params.end_date || new Date();
  var startDate = moment(start).startOf('month');
  var endDate = moment(end).endOf('month');

  transactions.totals(startDate.toDate(), endDate.toDate())
    .then(function(totals) {
      res.render('categories', {
        viewName: 'categories',
        totals: totals,
        startDate: startDate.format('YYYY/MM'),
        endDate: endDate.format('YYYY/MM')
      });
    }).catch(next);
}<commit_msg>categories view should show this month and the previous month<commit_after>var express = require('express');
var router = express.Router();
var transactions = require('../../controllers/transactions');
var moment = require('moment');

router.get('/', render);
router.get('/date/:year/:month', render);
router.get('/date/:year/:month/:category', render);

router.get('/categories', categories);
router.get('/categories/:start_date/:end_date', categories);
router.get('/import', function(req, res, next) {
  res.render('import', { viewName: 'import' });
});

module.exports = router;

function render(req, res, next) {
  var year = req.params.year;
  var month = req.params.month;
  var category = req.params.category;

  transactions.view({year, month}, category)
    .then(function(view) {
      res.render('index', view);
    }).catch(next);
}

function categories(req, res, next) {
  var start = req.params.start_date || new Date();
  var end = req.params.end_date || new Date();
  var startDate = moment(start).subtract(1, 'months').startOf('month');
  var endDate = moment(end).endOf('month');

  transactions.totals(startDate.toDate(), endDate.toDate())
    .then(function(totals) {
      res.render('categories', {
        viewName: 'categories',
        totals: totals,
        startDate: startDate.format('YYYY/MM'),
        endDate: endDate.format('YYYY/MM')
      });
    }).catch(next);
}
{'fraction_non_alphanumeric': 0.18548387096774194, 'fraction_numerical': 0.00036656891495601173, 'mean_word_length': 4.188212927756654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5189443', 'n_tokens_mistral': 837, 'n_tokens_neox': 848, 'n_words': 178}