-
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.
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 purposes to the return requirement summary card Previous work done here - #1019
- Loading branch information
1 parent
871cf63
commit d27c048
Showing
8 changed files
with
462 additions
and
305 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
32 changes: 32 additions & 0 deletions
32
app/services/return-requirements/check/fetch-purposes.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,32 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches a licence's purposes needed for `/return-requirements/{sessionId}/purpose` page | ||
* @module FetchPurposesByIdsService | ||
*/ | ||
|
||
const PurposeModel = require('../../../models/purpose.model.js') | ||
|
||
/** | ||
* Fetches a licence's purposes needed for `/return-requirements/{sessionId}/purpose` page | ||
* | ||
* @param {[string]} purposeIds - An array of ids to fetch | ||
* | ||
* @returns {Promise<Object>} The purposes matching the array of id's | ||
*/ | ||
async function go (purposeIds) { | ||
return _fetch(purposeIds) | ||
} | ||
|
||
async function _fetch (purposeIds) { | ||
return PurposeModel.query() | ||
.select([ | ||
'purposes.id', | ||
'purposes.description' | ||
]) | ||
.findByIds(purposeIds) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
65 changes: 65 additions & 0 deletions
65
app/services/return-requirements/check/returns-requirements.presenter.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,65 @@ | ||
'use strict' | ||
|
||
const { formatAbstractionDate } = require('../../../presenters/base.presenter.js') | ||
|
||
/** | ||
* Formats data for the `/return-requirements/{sessionId}/check` page | ||
* @module ReturnRequirementsPresenter | ||
*/ | ||
|
||
function go (requirements, purposeIds, 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) | ||
} | ||
} | ||
|
||
function _abstractionPeriod (abstractionPeriod) { | ||
const { 'start-abstraction-period-day': startDay, 'start-abstraction-period-month': startMonth, 'end-abstraction-period-day': endDay, 'end-abstraction-period-month': endMonth } = abstractionPeriod | ||
const startDate = formatAbstractionDate(startDay, startMonth) | ||
const endDate = formatAbstractionDate(endDay, endMonth) | ||
|
||
return `From ${startDate} to ${endDate}` | ||
} | ||
function _requirements (requirements, purposeIds) { | ||
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)) | ||
} | ||
} | ||
|
||
return completedRequirements | ||
} | ||
|
||
function _mapRequirement (requirement, index, purposeIds) { | ||
return { | ||
abstractionPeriod: _abstractionPeriod(requirement.abstractionPeriod), | ||
frequencyCollected: requirement.frequencyCollected, | ||
frequencyReported: requirement.frequencyReported, | ||
index, | ||
purposes: _mapPurpoes(requirement.purposes, purposeIds), | ||
siteDescription: requirement.siteDescription | ||
} | ||
} | ||
|
||
function _mapPurpoes (purposes, purposeIds) { | ||
const uniquePurposes = [...new Set(purposes)] | ||
|
||
return uniquePurposes.map((purpose) => { | ||
return purposeIds.find((pid) => { return pid.id === purpose }).description | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
44 changes: 44 additions & 0 deletions
44
app/services/return-requirements/check/returns-requirements.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,44 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the requirements for the check page | ||
* @module RequirementsService | ||
*/ | ||
|
||
const FetchPurposesByIdsService = require('./fetch-purposes.service.js') | ||
const ReturnRequirementsPresenter = require('./returns-requirements.presenter.js') | ||
const SessionModel = require('../../../models/session.model.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the requirements for `/return-requirements/{sessionId}/check` page | ||
* | ||
* @param {string} sessionId - The UUID for return requirement setup session record | ||
* | ||
* @returns {Promise<Object>} page data needed by the view template | ||
*/ | ||
async function go (sessionId) { | ||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
const { requirements, journey } = session | ||
const purposeIds = _purposeIds(requirements) | ||
const purposes = await FetchPurposesByIdsService.go(purposeIds) | ||
|
||
return ReturnRequirementsPresenter.go(requirements, purposes, journey) | ||
} | ||
|
||
function _purposeIds (requirements) { | ||
const requirementPurposes = requirements.flatMap((requirement) => { | ||
if (requirement.purposes) { | ||
return requirement.purposes | ||
} | ||
|
||
return [] | ||
}) | ||
|
||
// Duplicate is a bug this is temp | ||
return [...new Set(requirementPurposes)] | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
Oops, something went wrong.