-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature-requirements-for-returns-view-page (#1118)
* Add requirements for returns view page https://eaflood.atlassian.net/browse/WATER-4422 The requirements for return journey has been built and the check page has been finished. This showed a page with requirements for returns allowing users to make changes to requirements for returns. This piece of work will replicate the requirements for returns check page but will not allow users to make changes (the card and information is identical, apart from the title and a return reference). There will be a link "View" on the licence set up page that links to this page. That is added as part of this change. Work for this was done here - #1054
- Loading branch information
1 parent
be3ea9a
commit 8c76943
Showing
19 changed files
with
1,200 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats requirements for returns 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 | ||
* return version, licence, return requirements (requirement, points, purposes) | ||
* | ||
* @returns {Object} requirements for returns data needed by the view template | ||
*/ | ||
|
||
function go (requirementsForReturns) { | ||
const { createdAt, licence, reason, notes, multipleUpload, returnRequirements, startDate, status, user } = | ||
requirementsForReturns | ||
|
||
return { | ||
additionalSubmissionOptions: { | ||
multipleUpload: 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), | ||
createdDate: formatLongDate(createdAt), | ||
createdBy: user ? user.username : '' | ||
} | ||
} | ||
|
||
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), | ||
returnReference: requirement.legacyId, | ||
returnsCycle: requirement.summer === true ? 'Summer' : 'Winter and all year', | ||
siteDescription: requirement.siteDescription, | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/services/return-requirements/fetch-requirements-for-returns.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'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, return requirements (requirement, points, purposes) | ||
* | ||
* @param {string} returnVersionId - The UUID of the selected return version to get requirements for | ||
* | ||
* @returns {Promise<ReturnVersionModel[]>} | ||
* The return version, licence, return requirements (requirement, points, purposes) | ||
* | ||
*/ | ||
async function go (returnVersionId) { | ||
const returnVersion = await _fetch(returnVersionId) | ||
|
||
return returnVersion | ||
} | ||
|
||
async function _fetch (returnVersionId) { | ||
return ReturnVersionModel.query() | ||
.findById(returnVersionId) | ||
.select([ | ||
'createdAt', | ||
'id', | ||
'multiple_upload', | ||
'notes', | ||
'reason', | ||
'startDate', | ||
'status' | ||
]) | ||
.withGraphFetched('user') | ||
.modifyGraph('user', (builder) => { | ||
builder.select([ | ||
'username' | ||
]) | ||
}) | ||
.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 | ||
} |
Oops, something went wrong.