Skip to content

Commit

Permalink
Feature returns required points
Browse files Browse the repository at this point in the history
Due to the estimated complexity of adding fetch services for purposes, points and other display items. We have broken down the complex display items into their own branches of work.

https://eaflood.atlassian.net/browse/WATER-4386

This branch will add points to the return requirement summary card.

Previous work done here - #1019
  • Loading branch information
jonathangoulding committed Jun 4, 2024
1 parent d08e418 commit a05f262
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
'use strict'

const { formatAbstractionDate } = require('../../base.presenter.js')
const { generateAbstractionPointDetail } = require('../../../lib/general.lib.js')

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

function go (requirements, purposeIds, journey) {
function go (requirements, purposeIds, pointsData, journey) {
// Not clear of this can be an if else
const returnsRequired = journey === 'returns-required'
const noReturnsRequired = journey === 'no-returns-required'

return {
returnsRequired,
noReturnsRequired,
requirements: _requirements(requirements, purposeIds)
requirements: _requirements(requirements, purposeIds, pointsData)
}
}

Expand All @@ -26,15 +27,15 @@ function _abstractionPeriod (abstractionPeriod) {

return `From ${startDate} to ${endDate}`
}
function _requirements (requirements, purposeIds) {
function _requirements (requirements, purposeIds, pointsData) {
const completedRequirements = []

for (const [index, requirement] of requirements.entries()) {
const { agreementsExceptions } = requirement
// NOTE: We determine a requirement is complete because agreement exceptions is populated and it is the last step in
// the journey
if (agreementsExceptions) {
completedRequirements.push(_mapRequirement(requirement, index, purposeIds))
completedRequirements.push(_mapRequirement(requirement, index, purposeIds, pointsData))
}
}

Expand All @@ -47,17 +48,30 @@ function _mapPurposes (purposes, purposeIds) {
})
}

function _mapRequirement (requirement, index, purposeIds) {
function _mapRequirement (requirement, index, purposeIds, pointsData) {
return {
abstractionPeriod: _abstractionPeriod(requirement.abstractionPeriod),
frequencyCollected: requirement.frequencyCollected,
frequencyReported: requirement.frequencyReported,
index,
points: _mapPoints(requirement.points, pointsData),
purposes: _mapPurposes(requirement.purposes, purposeIds),
siteDescription: requirement.siteDescription
}
}

function _mapPoints (points, pointsData) {
if (!points) {
return []
}

return points.map((point) => {
const foundPoint = pointsData.find((pid) => { return pid.ID === point })

return generateAbstractionPointDetail(foundPoint)
})
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* @module ReturnRequirementsService
*/

const FetchPointsService = require('../fetch-points.service.js')
const PurposeModel = require('../../../models/purpose.model.js')
const ReturnRequirementsPresenter = require('../../../presenters/return-requirements/check/returns-requirements.presenter.js')
const SessionModel = require('../../../models/session.model.js')
const PurposeModel = require('../../../models/purpose.model.js')

/**
* Orchestrates fetching and presenting the return requirements for `/return-requirements/{sessionId}/check` page
Expand All @@ -22,8 +23,9 @@ async function go (sessionId) {
const { requirements, journey } = session
const purposeIds = _purposeIds(requirements)
const purposes = await _fetchPurposeIds(purposeIds)
const pointsData = await FetchPointsService.go(session.licence.id)

return ReturnRequirementsPresenter.go(requirements, purposes, journey)
return ReturnRequirementsPresenter.go(requirements, purposes, pointsData, journey)
}

function _purposeIds (requirements) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/return-requirements/check.njk
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
text: "Points"
},
value: {
html: "requirement.points"
html: newLine(requirement.points)
},
actions: {
items: [
Expand Down

0 comments on commit a05f262

Please sign in to comment.