Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display return versions in view licence setup tab #1054

Merged
merged 46 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
aec28f8
View licence set up returns for requirements
jonathangoulding May 28, 2024
d35336a
feat: add fetch returns structure
jonathangoulding May 29, 2024
07ccd8f
Merge remote-tracking branch 'origin/main' into feature-view-licence-…
jonathangoulding Jun 10, 2024
a238beb
feat: add fetch to return versions
jonathangoulding Jun 10, 2024
df3e3ea
chore: rename to returnVersions
jonathangoulding Jun 10, 2024
ccb3b9f
test: return versions
jonathangoulding Jun 11, 2024
65a2b03
test: return versions
jonathangoulding Jun 11, 2024
8bab828
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 11, 2024
18f84ad
fix: view file bad merge
jonathangoulding Jun 11, 2024
feebe7f
chore: pre pr
jonathangoulding Jun 11, 2024
08d919e
chore: pre pr
jonathangoulding Jun 11, 2024
fe74e4a
fix: button should be vertical
jonathangoulding Jun 11, 2024
cd660f1
refactor: toggle into config
jonathangoulding Jun 11, 2024
005839c
feat: order return versions by start date
jonathangoulding Jun 11, 2024
a1f50e4
fix: pre pr
jonathangoulding Jun 11, 2024
9727a06
test: toggle
jonathangoulding Jun 11, 2024
74cc3d3
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 12, 2024
371d42e
Update app/views/licences/tabs/set-up.njk
jonathangoulding Jun 12, 2024
1170b31
fix: move buttons behind flag
jonathangoulding Jun 12, 2024
2be0f9f
Update test/presenters/licences/set-up.presenter.test.js
jonathangoulding Jun 12, 2024
af1ab45
Update app/presenters/licences/set-up.presenter.js
jonathangoulding Jun 12, 2024
97b499e
fix: test undefined
jonathangoulding Jun 12, 2024
0c95818
Update app/presenters/licences/set-up.presenter.js
jonathangoulding Jun 12, 2024
d4eb69e
fix: use status mapper for return version status
jonathangoulding Jun 12, 2024
39a1286
chore: add ENABLE_REQUIREMENTS_FOR_RETURNS flag to env example
jonathangoulding Jun 12, 2024
b2a2cf3
refactor: setup heads into the components
jonathangoulding Jun 12, 2024
aadb1b9
chore: remove only tag
jonathangoulding Jun 12, 2024
48d5c60
test: fix service test status map
jonathangoulding Jun 12, 2024
e460d53
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 12, 2024
8bf5f57
test: fix service test status map
jonathangoulding Jun 12, 2024
14b7562
test: fix feature flag test with stub
jonathangoulding Jun 12, 2024
1bc85da
Update app/presenters/licences/set-up.presenter.js
jonathangoulding Jun 12, 2024
01cd54b
refactor: feature toggle into the presenter logic
jonathangoulding Jun 12, 2024
7972fa3
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 12, 2024
21b2b10
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 12, 2024
189c99b
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 13, 2024
56e4d77
Update app/services/licences/fetch-return-versions.service.js
jonathangoulding Jun 13, 2024
8d54263
fix: unnecessary double if to if else
jonathangoulding Jun 13, 2024
c725de6
Merge remote-tracking branch 'origin/feature-view-licence-returns-req…
jonathangoulding Jun 13, 2024
1637876
fix: feature flag location
jonathangoulding Jun 13, 2024
de0608f
fix: feature flag in service test
jonathangoulding Jun 13, 2024
2f245b5
fix: feature flag in service test
jonathangoulding Jun 13, 2024
e6ccb57
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 13, 2024
d49b1e1
chore: nit function alpha order
jonathangoulding Jun 13, 2024
2d92bb7
chore: sinon restore
jonathangoulding Jun 13, 2024
ee0b663
Merge branch 'main' into feature-view-licence-returns-requirements
jonathangoulding Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ COOKIE_SECRET=

# Feature flags
ENABLE_REISSUING_BILLING_BATCHES=false
ENABLE_REQUIREMENTS_FOR_RETURNS=false
49 changes: 42 additions & 7 deletions app/presenters/licences/set-up.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* @module SetUpPresenter
*/

const FeatureFlagsConfig = require('../../../config/feature-flags.config.js')
const { formatLongDate } = require('../base.presenter.js')
const { returnRequirementReasons } = require('../../lib/static-lookups.lib.js')

const roles = {
billing: 'billing',
Expand All @@ -27,18 +29,25 @@ const agreementDescriptions = {
*
* @param {module:ChargeVersionModel[]} chargeVersions - All charge versions records for the licence
* @param {module:WorkflowModel[]} workflows - All in-progress workflow records for the licence
* @param {module:LicenceAgreements[]} agreements - All agreements records for the licence
* @param {module:LicenceAgreementModel[]} agreements - All agreements records for the licence
* @param {module:ReturnVersionModel[]} returnVersions - All returns version records for the licence
* @param {Object} auth - The auth object taken from `request.auth` containing user details
* @param {Object} commonData - Licence data already formatted for the view's shared elements
*
* @returns {Object} The data formatted for the view template
*/
function go (chargeVersions, workflows, agreements, auth, commonData) {
function go (chargeVersions, workflows, agreements, returnVersions, auth, commonData) {
const enableRequirementsForReturns = FeatureFlagsConfig.enableRequirementsForReturns

return {
links: {
chargeInformation: _chargeInformationLinks(auth, commonData),
agreements: _agreementLinks(auth, commonData),
returnVersions: _returnVersionsLinks(commonData, enableRequirementsForReturns)
},
agreements: _agreements(commonData, agreements, auth),
chargeInformation: _chargeInformation(chargeVersions, workflows, auth),
..._agreementButtons(auth, commonData),
..._authorisedLinks(auth, commonData)
returnVersions: _returnVersions(returnVersions)
}
}

Expand Down Expand Up @@ -93,17 +102,17 @@ function _agreementActionLinks (commonData, agreement, auth) {
return actionLinks
}

function _agreementButtons (auth, commonData) {
function _agreementLinks (auth, commonData) {
if (auth.credentials.scope.includes(roles.manageAgreements) && !_endsSixYearsAgo(commonData.ends)) {
return {
setUpAgreement: `/licences/${commonData.licenceId}/agreements/select-type`
}
}

return null
return {}
}

function _authorisedLinks (auth, commonData) {
function _chargeInformationLinks (auth, commonData) {
if (auth.credentials.scope.includes(roles.workflowEditor) && !_endsSixYearsAgo(commonData.ends)) {
return {
setupNewCharge: `/licences/${commonData.licenceId}/charge-information/create`,
Expand Down Expand Up @@ -161,6 +170,32 @@ function _financialAgreementCode (agreement) {
return agreement.financialAgreements[0].financialAgreementCode
}

function _returnVersions (returnVersions = [{}]) {
return returnVersions.map((returnVersion) => {
return {
action: [{
text: 'View',
link: ''
}],
endDate: returnVersion.endDate ? formatLongDate(returnVersion.endDate) : '',
reason: returnVersion.reason ? returnRequirementReasons[returnVersion.reason] : '',
startDate: formatLongDate(returnVersion.startDate),
status: _status(returnVersion.status)
}
})
}

function _returnVersionsLinks (commonData, enableRequirementsForReturns) {
if (enableRequirementsForReturns) {
return {
returnsRequired: `/system/licences/${commonData.licenceId}/returns-required`,
noReturnsRequired: `/system/licences/${commonData.licenceId}/no-returns-required`
}
}

return {}
}

function _status (status) {
const statuses = {
current: 'approved',
Expand Down
38 changes: 38 additions & 0 deletions app/services/licences/fetch-return-versions.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

/**
* Fetches return requirements data needed for the view '/licences/{id}/set-up` page
* @module FetchReturnVersionsService
*/

const ReturnVersionModel = require('../../models/return-version.model.js')

/**
* Fetches return requirements data needed for the view '/licences/{id}/set-up` page
*
* @param {string} licenceId - The licence id for the licence to fetch return requirements
*
* @returns {Promise<Object>} the data needed to populate the view licence page's set up tab
*/
async function go (licenceId) {
return _fetch(licenceId)
}

async function _fetch (licenceId) {
return ReturnVersionModel.query()
.select([
'id',
'startDate',
'endDate',
'status',
'reason'
])
.where('licenceId', licenceId)
.orderBy([
{ column: 'startDate', order: 'desc' }
])
}

module.exports = {
go
}
5 changes: 4 additions & 1 deletion app/services/licences/view-licence-set-up.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const FetchAgreementsService = require('./fetch-agreements.service.js')
const FetchChargeVersionsService = require('./fetch-charge-versions.service.js')
const FetchReturnVersionsService = require('./fetch-return-versions.service.js')
const FetchWorkflowsService = require('./fetch-workflows.service.js')
const SetUpPresenter = require('../../presenters/licences/set-up.presenter.js')
const ViewLicenceService = require('./view-licence.service.js')
Expand All @@ -25,8 +26,10 @@ async function go (licenceId, auth) {
const agreements = await FetchAgreementsService.go(commonData.licenceRef)
const chargeVersions = await FetchChargeVersionsService.go(licenceId)
const workflows = await FetchWorkflowsService.go(licenceId)
const returnVersions = await FetchReturnVersionsService.go(licenceId)

const licenceSetUpData = SetUpPresenter.go(chargeVersions, workflows, agreements, auth, commonData)
const licenceSetUpData = SetUpPresenter
.go(chargeVersions, workflows, agreements, returnVersions, auth, commonData)

return {
activeTab: 'set-up',
Expand Down
Loading
Loading