Skip to content

Commit

Permalink
Tidy up two-part tariff review code and routes (#1443)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4739

We have completed the annual billing engine for the two-part tariff. The matching and allocating engine, including the pages used to review the results, has been tested.

However, we started this work more than 12 months ago when our understanding of what was required was at 0%! We were also in the infancy of adding and working with pages in [water-abstraction-system](https://github.com/DEFRA/water-abstraction-system).

So, we made choices that, in hindsight, we would have done differently. Essentially, all our code to support reviewing a bill run is mixed in with the code to generate the matching and allocating results and the bill itself. From a maintenance viewpoint, it becomes hard to understand the context of the various modules because they have all been thrown into the same basket.

We’re now about to add a bunch more code to deliver WATER-4201 .

To ensure the project remains within our levels of tolerance for code maintenance, we need to do some prep work before starting WATER-4201 .

That prep work includes

- Move the existing ‘review’ routes to their own dedicated /bill-runs/review root URL
- Split the existing route's in two
- Split the existing controller's file in two
- Move review-related presenters into their own presenters/bill-runs/review folder
- Move review-related services into their own services/bill-runs/review folder
- Move review-related validators into their own validators/bill-runs/review folder
- Move review-related views into their own views/bill-runs/review folder
- Update module names to reflect existing naming conventions
- Update URL’s to use record ID’s rather than derived, for example, review licence ID instead of bill run ID & licence ID

We also include lots of refactoring and housekeeping, simplifying both the modules and their tests, and ensuring better consistency. We've also managed to correct some issues found, for example, inconsistency with nav menu selection, error bookmarks not working, and some errant spacing.
  • Loading branch information
Cruikshanks authored Nov 7, 2024
1 parent 769020e commit 1068930
Show file tree
Hide file tree
Showing 152 changed files with 7,889 additions and 8,239 deletions.
210 changes: 210 additions & 0 deletions app/controllers/bill-runs-review.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
'use strict'

/**
* Controller for /bill-runs/review endpoints
* @module BillRunsReviewController
*/

const AuthorisedService = require('../services/bill-runs/review/authorised.service.js')
const FactorsService = require('../services/bill-runs/review/factors.service.js')
const EditService = require('../services/bill-runs/review/edit.service.js')
const PreviewService = require('../services/bill-runs/review/preview.service.js')
const RemoveService = require('../services/bill-runs/review/remove.service.js')
const ReviewChargeElementService = require('../services/bill-runs/review/review-charge-element.service.js')
const ReviewChargeReferenceService = require('../services/bill-runs/review/review-charge-reference.service.js')
const ReviewBillRunService = require('../services/bill-runs/review/review-bill-run.service.js')
const ReviewLicenceService = require('../services/bill-runs/review/review-licence.service.js')
const SubmitAuthorisedService = require('../services/bill-runs/review/submit-authorised.service.js')
const SubmitEditService = require('..//services/bill-runs/review/submit-edit.service.js')
const SubmitFactorsService = require('../services/bill-runs/review/submit-factors.service.js')
const SubmitRemoveService = require('../services/bill-runs/review/submit-remove.service.js')
const SubmitReviewBillRunService = require('../services/bill-runs/review/submit-review-bill-run.service.js')
const SubmitReviewLicenceService = require('../services/bill-runs/review/submit-review-licence.service.js')

async function authorised (request, h) {
const { reviewChargeReferenceId } = request.params

const pageData = await AuthorisedService.go(reviewChargeReferenceId)

return h.view('bill-runs/review/authorised.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function edit (request, h) {
const { elementIndex, reviewChargeElementId } = request.params

const pageData = await EditService.go(reviewChargeElementId, elementIndex)

return h.view('bill-runs/review/edit.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function factors (request, h) {
const { reviewChargeReferenceId } = request.params

const pageData = await FactorsService.go(reviewChargeReferenceId)

return h.view('bill-runs/review/factors.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function preview (request, h) {
const { reviewChargeReferenceId } = request.params

await PreviewService.go(reviewChargeReferenceId, request.yar)

return h.redirect(`/system/bill-runs/review/charge-reference/${reviewChargeReferenceId}`)
}

async function remove (request, h) {
const { reviewLicenceId } = request.params

const pageData = await RemoveService.go(reviewLicenceId)

return h.view('bill-runs/review/remove.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function reviewBillRun (request, h) {
const { billRunId } = request.params
const { page } = request.query

const pageData = await ReviewBillRunService.go(billRunId, page, request.yar)

return h.view('bill-runs/review/review.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function reviewChargeElement (request, h) {
const { elementIndex, reviewChargeElementId } = request.params

const pageData = await ReviewChargeElementService.go(reviewChargeElementId, elementIndex, request.yar)

return h.view('bill-runs/review/review-charge-element.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function reviewChargeReference (request, h) {
const { reviewChargeReferenceId } = request.params

const pageData = await ReviewChargeReferenceService.go(reviewChargeReferenceId, request.yar)

return h.view('bill-runs/review/review-charge-reference.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function reviewLicence (request, h) {
const { reviewLicenceId } = request.params

const pageData = await ReviewLicenceService.go(reviewLicenceId, request.yar)

return h.view('bill-runs/review/review-licence.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

async function submitAuthorised (request, h) {
const { reviewChargeReferenceId } = request.params
const pageData = await SubmitAuthorisedService.go(reviewChargeReferenceId, request.yar, request.payload)

if (pageData.error) {
return h.view('bill-runs/review/authorised.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

return h.redirect(`/system/bill-runs/review/charge-reference/${reviewChargeReferenceId}`)
}

async function submitEdit (request, h) {
const { elementIndex, reviewChargeElementId } = request.params

const pageData = await SubmitEditService.go(
reviewChargeElementId, elementIndex, request.yar, request.payload
)

if (pageData.error) {
return h.view('bill-runs/review/edit.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

return h.redirect(`/system/bill-runs/review/charge-element/${reviewChargeElementId}/${elementIndex}`)
}

async function submitFactors (request, h) {
const { reviewChargeReferenceId } = request.params
const pageData = await SubmitFactorsService.go(reviewChargeReferenceId, request.yar, request.payload)

if (pageData.error) {
return h.view('bill-runs/review/factors.njk', {
activeNavBar: 'bill-runs',
...pageData
})
}

return h.redirect(`/system/bill-runs/review/charge-reference/${reviewChargeReferenceId}`)
}

async function submitRemove (request, h) {
const { reviewLicenceId } = request.params

const result = await SubmitRemoveService.go(reviewLicenceId, request.yar)

if (result.empty) {
return h.redirect('/system/bill-runs')
}

return h.redirect(`/system/bill-runs/review/${result.billRunId}`)
}

async function submitReviewBillRun (request, h) {
const { billRunId } = request.params

await SubmitReviewBillRunService.go(billRunId, request.payload, request.yar)

return h.redirect(`/system/bill-runs/review/${billRunId}`)
}

async function submitReviewLicence (request, h) {
const { reviewLicenceId } = request.params

await SubmitReviewLicenceService.go(reviewLicenceId, request.yar, request.payload)

return h.redirect(`/system/bill-runs/review/licence/${reviewLicenceId}`)
}

module.exports = {
authorised,
edit,
factors,
preview,
remove,
reviewBillRun,
reviewChargeElement,
reviewChargeReference,
reviewLicence,
submitAuthorised,
submitEdit,
submitFactors,
submitRemove,
submitReviewBillRun,
submitReviewLicence
}
Loading

0 comments on commit 1068930

Please sign in to comment.