From a05f26267ec2c04eaf4c2d0d006774e73df57af0 Mon Sep 17 00:00:00 2001 From: jonathangoulding Date: Tue, 4 Jun 2024 11:42:25 +0100 Subject: [PATCH] Feature returns required points 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 - https://github.com/DEFRA/water-abstraction-system/pull/1019 --- .../check/returns-requirements.presenter.js | 24 +++++++++++++++---- .../check/returns-requirements.service.js | 6 +++-- app/views/return-requirements/check.njk | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/presenters/return-requirements/check/returns-requirements.presenter.js b/app/presenters/return-requirements/check/returns-requirements.presenter.js index 1645cba299..7416641f9f 100644 --- a/app/presenters/return-requirements/check/returns-requirements.presenter.js +++ b/app/presenters/return-requirements/check/returns-requirements.presenter.js @@ -1,13 +1,14 @@ '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' @@ -15,7 +16,7 @@ function go (requirements, purposeIds, journey) { return { returnsRequired, noReturnsRequired, - requirements: _requirements(requirements, purposeIds) + requirements: _requirements(requirements, purposeIds, pointsData) } } @@ -26,7 +27,7 @@ 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()) { @@ -34,7 +35,7 @@ function _requirements (requirements, purposeIds) { // 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)) } } @@ -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 } diff --git a/app/services/return-requirements/check/returns-requirements.service.js b/app/services/return-requirements/check/returns-requirements.service.js index f5213e6957..e8b1263396 100644 --- a/app/services/return-requirements/check/returns-requirements.service.js +++ b/app/services/return-requirements/check/returns-requirements.service.js @@ -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 @@ -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) { diff --git a/app/views/return-requirements/check.njk b/app/views/return-requirements/check.njk index 1ebf53471a..0774eaa8d0 100644 --- a/app/views/return-requirements/check.njk +++ b/app/views/return-requirements/check.njk @@ -147,7 +147,7 @@ text: "Points" }, value: { - html: "requirement.points" + html: newLine(requirement.points) }, actions: { items: [