Skip to content

Commit

Permalink
Update the check service to use our new presenters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks committed Jan 26, 2025
1 parent b5d6ead commit ce282a4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/services/bill-runs/setup/check.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
* @module CheckService
*/

const CheckPresenter = require('../../../presenters/bill-runs/setup/check.presenter.js')
const AllowedBillRunPresenter = require('../../../presenters/bill-runs/setup/check/allowed-bill-run.presenter.js')
const BlockedBillRunPresenter = require('../../../../app/presenters/bill-runs/setup/check/blocked-bill-run.presenter.js')
const NoAnnualBillRunPresenter = require('../../../presenters/bill-runs/setup/check/no-annual-bill-run.presenter.js')
const DetermineBlockingBillRunService = require('./determine-blocking-bill-run.service.js')
const SessionModel = require('../../../models/session.model.js')
const { engineTriggers } = require('../../../../app/lib/static-lookups.lib.js')

/**
* Orchestrates fetching and presenting the data for `/bill-runs/setup/{sessionId}/check` page
Expand All @@ -18,16 +21,28 @@ const SessionModel = require('../../../models/session.model.js')
*/
async function go(sessionId) {
const session = await SessionModel.query().findById(sessionId)

const blockingResults = await DetermineBlockingBillRunService.go(session)
const formattedData = await CheckPresenter.go(session, blockingResults)

const formattedData = _formattedData(session, blockingResults)

return {
activeNavBar: 'bill-runs',
...formattedData
}
}

function _formattedData(session, blockingResults) {
if (blockingResults.toFinancialYearEnding === 0) {
return NoAnnualBillRunPresenter.go(session)
}

if (blockingResults.trigger === engineTriggers.neither) {
return BlockedBillRunPresenter.go(session, blockingResults)
}

return AllowedBillRunPresenter.go(session, blockingResults)
}

module.exports = {
go
}

0 comments on commit ce282a4

Please sign in to comment.