<commit_before>const getUtilisationTable = require('../services/get-utilisation-table')
const UtilisationDate = require('../services/domain/utilisation-date')
const ORG_UNIT_TYPE = require('../constants/organisation-unit-type-enum')
const dateFormatter = require('../services/date-formatter')

module.exports = function (router) {
  router.get(`/caseload-utilisation/${ORG_UNIT_TYPE.OFFENDER_MANAGER}/:id/`, function (req, res, next) {

    var fromUtilisationDate, toUtilisationDate

    if(Object.keys(req.query).length === 0) {
      fromDate = dateFormatter.now().subtract(1, "years")
      toDate = dateFormatter.now()

      fromUtilisationDate = new UtilisationDate(
        fromDate.date(),
        fromDate.month() +1,
        fromDate.year()
      )
      toUtilisationDate = new UtilisationDate(
        toDate.date(),
        toDate.month() +1,
        toDate.year()
      )
    } else {
      fromUtilisationDate = new UtilisationDate(
        req.query['utilisation-from-year'],
        req.query['utilisation-from-month'],
        req.query['utilisation-from-day']
      )
      toUtilisationDate = new UtilisationDate(
        req.query['utilisation-to-year'],
        req.query['utilisation-to-month'],
        req.query['utilisation-to-day']
      )
    }

    return res.render('utilisation', {
      utilisation: getUtilisationTable(ORG_UNIT_TYPE.OFFENDER_MANAGER, req.params.id, fromUtilisationDate, toUtilisationDate)
    })
  })
}<commit_msg>WMT-275: updated offender manager utilisation route to include validation and to correct date input order<commit_after>const getUtilisationTable = require('../services/get-utilisation-table')
const UtilisationDate = require('../services/domain/utilisation-date')
const ORG_UNIT_TYPE = require('../constants/organisation-unit-type-enum')
const dateFormatter = require('../services/date-formatter')
const ValidationError = require('../services/errors/validation-error')

module.exports = function (router) {
  router.get(`/caseload-utilisation/${ORG_UNIT_TYPE.OFFENDER_MANAGER}/:id/`, function (req, res, next) {

    try {
      var fromUtilisationDate, toUtilisationDate

      if(Object.keys(req.query).length === 0) {
        fromDate = dateFormatter.now().subtract(1, "years")
        toDate = dateFormatter.now()

        fromUtilisationDate = new UtilisationDate(
          fromDate.date(),
          fromDate.month() +1,
          fromDate.year()
        )
        toUtilisationDate = new UtilisationDate(
          toDate.date(),
          toDate.month() +1,
          toDate.year()
        )
      } else {

        fromUtilisationDate = new UtilisationDate(
          req.query['utilisation-from-day'],
          req.query['utilisation-from-month'],
          req.query['utilisation-from-year']
        )
        toUtilisationDate = new UtilisationDate(
          req.query['utilisation-to-day'],
          req.query['utilisation-to-month'],
          req.query['utilisation-to-year']
        )
      }

      return res.render('utilisation', {
        utilisation: getUtilisationTable(ORG_UNIT_TYPE.OFFENDER_MANAGER, req.params.id, fromUtilisationDate, toUtilisationDate)
      })

    } catch (error) {
      if (error instanceof ValidationError) {
        return res.status(400).render('utilisation', {
          errors: error.validationErrors,
          // claimType: req.params.claimType,
          // claimant: req.body
        })
      } else {
        throw error
      }
    }
  })
}
{'fraction_non_alphanumeric': 0.13127524523946912, 'fraction_numerical': 0.004039238315060588, 'mean_word_length': 2.8098901098901097, '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': '662074', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1013, 'n_words': 163}