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

Feature-requirements-for-returns-view-page #1118

Merged
merged 27 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c27f49
Add requirements for returns view page
jonathangoulding Jun 18, 2024
f0469b4
Add requirements for returns view page
jonathangoulding Jun 18, 2024
3ccc670
feat: add logic to display view
jonathangoulding Jun 19, 2024
5724f2a
feat: add note
jonathangoulding Jun 19, 2024
8fe036b
test: view presenter and fetch service
jonathangoulding Jun 19, 2024
3b8d1db
test: services
jonathangoulding Jun 19, 2024
1130418
test: licence id and ref
jonathangoulding Jun 19, 2024
cc7e3a9
fix: unused arg
jonathangoulding Jun 19, 2024
8789798
Merge branch 'main' into feature-requirements-for-returns-view-page
jonathangoulding Jun 20, 2024
a4c5fc1
chore: update generatePointDetail jsdocs
jonathangoulding Jun 20, 2024
5d9dd92
chore: pre pr check
jonathangoulding Jun 20, 2024
f4e757a
chore: pre pr check
jonathangoulding Jun 20, 2024
4b1ea51
chore: pre pr check
jonathangoulding Jun 20, 2024
04d3395
chore: pre pr check
jonathangoulding Jun 20, 2024
df4d46d
Merge branch 'main' into feature-requirements-for-returns-view-page
jonathangoulding Jun 20, 2024
377f921
refactor: notes to new design
jonathangoulding Jun 21, 2024
5519d13
refactor: update check note section to new design
jonathangoulding Jun 21, 2024
ed0e247
feat: add created by and at
jonathangoulding Jun 21, 2024
a44160d
Merge branch 'main' into feature-requirements-for-returns-view-page
jonathangoulding Jun 21, 2024
3348942
feat: add created by and at
jonathangoulding Jun 21, 2024
e139411
Merge branch 'main' into feature-requirements-for-returns-view-page
jonathangoulding Jun 21, 2024
557614d
fix: sonar cloud optional chaining
jonathangoulding Jun 21, 2024
260008c
Merge remote-tracking branch 'origin/feature-requirements-for-returns…
jonathangoulding Jun 21, 2024
8182deb
fix: use nlbr
jonathangoulding Jun 21, 2024
2cf2f62
feat: handle empty returnRequirements
jonathangoulding Jun 21, 2024
cce406c
fix: double not content check
jonathangoulding Jun 21, 2024
d52f5b8
fix: pre pr check
jonathangoulding Jun 21, 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
13 changes: 12 additions & 1 deletion app/controllers/return-requirements.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const SubmitReturnsCycleService = require('../services/return-requirements/submi
const SubmitSetupService = require('../services/return-requirements/setup/submit-setup.service.js')
const SubmitSiteDescriptionService = require('../services/return-requirements/submit-site-description.service.js')
const SubmitStartDateService = require('../services/return-requirements/submit-start-date.service.js')
const ViewService = require('../services/return-requirements/view.service.js')

async function abstractionPeriod (request, h) {
const { requirementIndex, sessionId } = request.params
Expand Down Expand Up @@ -494,6 +495,15 @@ async function submitStartDate (request, h) {
return h.redirect(`/system/return-requirements/${sessionId}/no-returns-required`)
}

async function view (request, h) {
const { returnVersionId } = request.params
const pageData = await ViewService.go(returnVersionId)

return h.view('return-requirements/view.njk', {
...pageData
})
}

module.exports = {
abstractionPeriod,
add,
Expand Down Expand Up @@ -533,5 +543,6 @@ module.exports = {
submitReturnsCycle,
submitSetup,
submitSiteDescription,
submitStartDate
submitStartDate,
view
}
31 changes: 31 additions & 0 deletions app/lib/general.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ function generateAbstractionPointDetail (pointDetail) {
return abstractionPoint
}

/**
* Generate a string that represents an abstraction point based on the new data (obs change this in PR)
*
*/
function generatePointDetail (point) {
let abstractionPoint = null

if (point.ngr4) {
const point1 = point.ngr1
const point2 = point.ngr2
const point3 = point.ngr3
const point4 = point.ngr4

abstractionPoint = `Within the area formed by the straight lines running between National Grid References ${point1} ${point2} ${point3} and ${point4}`
} else if (point.ngr2) {
const point1 = point.ngr1
const point2 = point.ngr2

abstractionPoint = `Between National Grid References ${point1} and ${point2}`
} else {
const point1 = point.ngr1

abstractionPoint = `At National Grid Reference ${point1}`
}

abstractionPoint += point.description !== undefined ? ` (${point.description})` : ''

return abstractionPoint
}

/**
* Generate a Universally Unique Identifier (UUID)
*
Expand Down Expand Up @@ -295,6 +325,7 @@ module.exports = {
determineCurrentFinancialYear,
flashNotification,
generateAbstractionPointDetail,
generatePointDetail,
generateUUID,
periodsOverlap,
timestampForPostgres,
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/licences/set-up.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function _returnVersions (returnVersions = [{}]) {
return {
action: [{
text: 'View',
link: ''
link: `/system/return-requirements/${returnVersion.id}/view`
}],
endDate: returnVersion.endDate ? formatLongDate(returnVersion.endDate) : '',
reason: returnVersion.reason ? returnRequirementReasons[returnVersion.reason] : '',
Expand Down
139 changes: 139 additions & 0 deletions app/presenters/return-requirements/view.presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
'use strict'

/**
* Formats return requirements data for the `/return-requirements/{sessionId}/view` page
* @module ViewPresenter
*/

const { formatAbstractionDate } = require('../base.presenter.js')
const { formatLongDate } = require('../base.presenter.js')
const { generatePointDetail } = require('../../lib/general.lib.js')
const { returnRequirementReasons, returnRequirementFrequencies } = require('../../lib/static-lookups.lib.js')

/**
* Formats requirements for returns data for the `/return-requirements/{sessionId}/view` page
*
* @param {ReturnVersionModel[]} requirementsForReturns - The return version inc licence and requirements
*
* @returns {Object} returns requirement data needed by the view template
*/

function go (requirementsForReturns) {
const { returnRequirements, licence, reason, startDate, status, notes } = requirementsForReturns

return {
additionalSubmissionOptions: {
multipleUpload: requirementsForReturns.multipleUpload === true ? 'Yes' : 'No'
},
licenceId: licence.id,
licenceRef: licence.licenceRef,
notes,
pageTitle: `Check the requirements for returns for ${licence.$licenceHolder()}`,
reason: returnRequirementReasons[reason] || '',
requirements: _requirements(returnRequirements),
startDate: formatLongDate(startDate),
status: _status(status)
}
}

function _abstractionPeriod (requirement) {
const {
abstractionPeriodStartDay,
abstractionPeriodStartMonth,
abstractionPeriodEndDay,
abstractionPeriodEndMonth
} = requirement

const startDate = formatAbstractionDate(abstractionPeriodStartDay, abstractionPeriodStartMonth)
const endDate = formatAbstractionDate(abstractionPeriodEndDay, abstractionPeriodEndMonth)

return `From ${startDate} to ${endDate}`
}

function _agreementsExceptions (returnRequirement) {
const agreementsExceptions = _buildAgreementExceptions(returnRequirement)

if (agreementsExceptions.length === 1) {
return agreementsExceptions[0]
}

if (agreementsExceptions.length === 2) {
return agreementsExceptions.join(' and ')
}

return agreementsExceptions.slice(0, agreementsExceptions.length - 1)
.join(', ') + ', and ' + agreementsExceptions[agreementsExceptions.length - 1]
}

function _buildAgreementExceptions (returnRequirement) {
const { fiftySixException, gravityFill, reabstraction, twoPartTariff } = returnRequirement
const agreementsExceptions = []

if (gravityFill) {
agreementsExceptions.push('Gravity fill')
}

if (reabstraction) {
agreementsExceptions.push('Transfer re-abstraction scheme')
}

if (twoPartTariff) {
agreementsExceptions.push('Two-part tariff')
}

if (fiftySixException) {
agreementsExceptions.push('56 returns exception')
}

if (agreementsExceptions.length === 0) {
agreementsExceptions.push('None')
}

return agreementsExceptions
}

function _mapRequirement (requirement) {
return {
abstractionPeriod: _abstractionPeriod(requirement),
agreementsExceptions: _agreementsExceptions(requirement),
frequencyCollected: returnRequirementFrequencies[requirement.collectionFrequency],
frequencyReported: returnRequirementFrequencies[requirement.reportingFrequency],
points: _points(requirement.points),
purposes: _purposes(requirement.purposes),
returnsCycle: requirement.summer === true ? 'Summer' : 'Winter and all year',
siteDescription: requirement.siteDescription,
returnReference: requirement.legacyId,
title: requirement.siteDescription
}
}

function _purposes (returnRequirementPurposes) {
return returnRequirementPurposes.map((returnRequirementPurpose) => {
return returnRequirementPurpose.purposeDetails.description
})
}

function _points (returnRequirementPoints) {
return returnRequirementPoints.map((returnRequirementPoint) => {
return generatePointDetail(returnRequirementPoint)
})
}

function _requirements (requirements) {
return requirements.map((requirement) => {
return _mapRequirement(requirement)
})
}

function _status (status) {
const statuses = {
current: 'approved',
superseded: 'replaced'
}

return statuses[status]
}

module.exports = {
go
}
12 changes: 12 additions & 0 deletions app/routes/return-requirement.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ const routes = [
}
}
}
},
{
method: 'GET',
path: '/return-requirements/{returnVersionId}/view',
handler: ReturnRequirementsController.view,
options: {
auth: {
access: {
scope: ['billing']
}
}
}
}
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict'

/**
* Fetches requirements for returns by the return version id
* @module FetchRequirementsForReturnsService
*/

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

/**
* Fetches requirements for returns by the return version id
*
* Includes the licence
*
* Formats the requirements
*
* @param {string} returnVersionId - The UUID of the selected return version to get requirements for
*
* @returns {Promise<Object>} The return version and its linked return requirements, plus their points and purposes
*/
async function go (returnVersionId) {
const returnVersion = await _fetch(returnVersionId)

return returnVersion
}

async function _fetch (returnVersionId) {
return ReturnVersionModel.query()
.findById(returnVersionId)
.select([
'id',
'multiple_upload',
'notes',
'reason',
'startDate',
'status'
])
.withGraphFetched('licence')
.modifyGraph('licence', (builder) => {
builder.select([
'id',
'licenceRef'
]).modify('licenceHolder')
})
.withGraphFetched('returnRequirements')
.modifyGraph('returnRequirements', (builder) => {
builder.select([
'abstractionPeriodEndDay',
'abstractionPeriodEndMonth',
'abstractionPeriodStartDay',
'abstractionPeriodStartMonth',
'collectionFrequency',
'fiftySixException',
'gravityFill',
'id',
'legacyId',
'reabstraction',
'reportingFrequency',
'siteDescription',
'summer',
'twoPartTariff'
])
})
.withGraphFetched('returnRequirements.[returnRequirementPoints as points]')
.modifyGraph('returnRequirements.[returnRequirementPoints as points]', (builder) => {
builder.select([
'description',
'ngr1',
'ngr2',
'ngr3',
'ngr4'
])
})
.withGraphFetched('returnRequirements.[returnRequirementPurposes as purposes.[purpose as purposeDetails]]')
.modifyGraph('returnRequirements.[returnRequirementPurposes as purposes]', (builder) => {
builder.select(['id'])
})
.modifyGraph('returnRequirements.[returnRequirementPurposes as purposes.[purpose as purposeDetails]]', (builder) => {
builder.select(['description'])
})
}

module.exports = {
go
}
31 changes: 31 additions & 0 deletions app/services/return-requirements/view.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

/**
* Orchestrates fetching and presenting the data for `/return-requirements/{sessionId}/view` page
* @module ViewService
*/

const FetchRequirementsForReturnsService = require('./fetch-requirements-for-returns.service.js')
const ViewPresenter = require('../../presenters/return-requirements/view.presenter.js')

/**
* Orchestrates fetching and presenting the data for `/return-requirements/{sessionId}/view` page
*
* @param {string} returnVersionId - The UUID for return requirement version
*
* @returns {Promise<Object>} page data needed by the view template
*/
async function go (returnVersionId) {
const requirementsForReturns = await FetchRequirementsForReturnsService.go(returnVersionId)

const data = ViewPresenter.go(requirementsForReturns)

return {
activeNavBar: 'search',
...data
}
}

module.exports = {
go
}
Loading
Loading