Skip to content

Commit

Permalink
refactor: check presenter maps a specific object to the view
Browse files Browse the repository at this point in the history
Alpha function order

Alpha object order
  • Loading branch information
jonathangoulding committed May 29, 2024
1 parent 18867cc commit d6fe389
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
27 changes: 18 additions & 9 deletions app/presenters/return-requirements/check.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ function go (session) {
}
}

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 _reasonLink (sessionId, journey) {
if (journey === 'returns-required') {
return `/system/return-requirements/${sessionId}/reason`
Expand All @@ -44,21 +52,22 @@ function _requirements (session) {
// NOTE: We determine a requirement is complete because agreement exceptions is populated and it is the last step in
// the journey
if (agreementsExceptions) {
requirement.abstractionPeriod = _abstractionPeriod(requirement.abstractionPeriod)
requirement.index = index
completedRequirements.push(requirement)
completedRequirements.push(_mapRequirement(requirement, index))
}
}

return completedRequirements
}

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 _mapRequirement (requirement, index) {
return {
abstractionPeriod: _abstractionPeriod(requirement.abstractionPeriod),
frequencyCollected: requirement.frequencyCollected,
frequencyReported: requirement.frequencyReported,
index,
purposes: 'purpose',
siteDescription: requirement.siteDescription
}
}

function _startDate (session) {
Expand Down
20 changes: 9 additions & 11 deletions app/views/return-requirements/check.njk
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
}) }}
</form>
{% for requirement in requirements %}
{# Set an easier to use index #}
{% set rowIndex = requirement.index %}
<div>
{{ govukSummaryList({
card: {
Expand All @@ -130,7 +128,7 @@
actions: {
items: [
{
href: "purpose/" + rowIndex,
href: "purpose/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Purpose"
}
Expand All @@ -147,7 +145,7 @@
actions: {
items: [
{
href: "points/" + rowIndex,
href: "points/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Point"
}
Expand All @@ -164,7 +162,7 @@
actions: {
items: [
{
href: "abstraction-period/" + rowIndex,
href: "abstraction-period/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Abstraction period"
}
Expand All @@ -181,7 +179,7 @@
actions: {
items: [
{
href: "returns-cycle/" + rowIndex,
href: "returns-cycle/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Returns cycle"
}
Expand All @@ -198,7 +196,7 @@
actions: {
items: [
{
href: "site-description/" + rowIndex,
href: "site-description/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Site description"
}
Expand All @@ -215,7 +213,7 @@
actions: {
items: [
{
href: "frequency-collected/" + rowIndex,
href: "frequency-collected/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Collection"
}
Expand All @@ -232,7 +230,7 @@
actions: {
items: [
{
href: "frequency-reported/" + rowIndex,
href: "frequency-reported/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Reporting"
}
Expand All @@ -249,7 +247,7 @@
actions: {
items: [
{
href: "agreements-exceptions/" + rowIndex,
href: "agreements-exceptions/" + requirement.index ,
text: "Change",
visuallyHiddenText: "Agreements exception"
}
Expand All @@ -263,7 +261,7 @@
text: "Remove requirement",
classes: "govuk-button--warning",
preventDoubleClick: true,
href: "/system/return-requirements/" + sessionId + "/remove/" + rowIndex
href: "/system/return-requirements/" + sessionId + "/remove/" + requirement.index
}) }}
{% endif %}
</div>
Expand Down

0 comments on commit d6fe389

Please sign in to comment.