-
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.
Merge branch 'main' into check-return-logs-change-links
- Loading branch information
Showing
35 changed files
with
1,857 additions
and
68 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
96 changes: 96 additions & 0 deletions
96
app/presenters/notifications/setup/download-recipients.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,96 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats data for the `/notifications/setup/download` link | ||
* @module DownloadRecipientsPresenter | ||
*/ | ||
|
||
const { contactName } = require('../../crm.presenter.js') | ||
const { formatDateObjectToISO } = require('../../../lib/dates.lib.js') | ||
const { transformArrayToCSVRow } = require('../../../lib/transform-to-csv.lib.js') | ||
|
||
const HEADERS = [ | ||
'Licences', | ||
'Return references', | ||
'Returns period start date', | ||
'Returns period end date', | ||
'Returns due date', | ||
'Message type', | ||
'Message reference', | ||
'Email', | ||
'Recipient name', | ||
'Address line 1', | ||
'Address line 2', | ||
'Address line 3', | ||
'Address line 4', | ||
'Address line 5', | ||
'Address line 6', | ||
'Postcode' | ||
] | ||
|
||
/** | ||
* Formats data for the `/notifications/setup/download` link. | ||
* | ||
* This function takes an array of recipient objects and transforms it into a CSV | ||
* string suitable for download. | ||
* | ||
* The headers are fixed and in the correct order. If a value for a row does not match the header then it will default | ||
* to an empty string. | ||
* | ||
* @param {object[]} recipients - An array of recipients | ||
* | ||
* @returns {string} - A CSV-formatted string that includes the recipients' data, with the first | ||
* row as column headers and subsequent rows corresponding to the recipient details. | ||
*/ | ||
function go(recipients) { | ||
const rows = _transformToCsv(recipients) | ||
|
||
return [HEADERS + '\n', ...rows].join('') | ||
} | ||
|
||
function _address(contact) { | ||
if (!contact) { | ||
return ['', '', '', '', '', '', ''] | ||
} | ||
|
||
return [ | ||
contact.addressLine1, | ||
contact.addressLine2, | ||
contact.addressLine3, | ||
contact.addressLine4, | ||
contact.town || contact.county, | ||
contact.country, | ||
contact.postcode | ||
] | ||
} | ||
/** | ||
* Transforms the recipients' data into a CSV-compatible format. | ||
* | ||
* The order of the object dictates the CSV header order. | ||
* | ||
* @private | ||
*/ | ||
function _transformToCsv(recipients) { | ||
return recipients.map((recipient) => { | ||
const { contact } = recipient | ||
|
||
const row = [ | ||
recipient.licence_ref, | ||
recipient.return_reference, | ||
formatDateObjectToISO(recipient.start_date), | ||
formatDateObjectToISO(recipient.end_date), | ||
formatDateObjectToISO(recipient.due_date), | ||
contact ? 'letter' : 'email', | ||
'invitations', | ||
recipient.email || '', | ||
contact ? contactName(recipient.contact) : '', | ||
..._address(contact) | ||
] | ||
|
||
return transformArrayToCSVRow(row) | ||
}) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict' | ||
|
||
/** | ||
* Format data for the `/return-log/setup/{sessionId}/period-used` page | ||
* @module PeriodUsedPresenter | ||
*/ | ||
|
||
const { formatAbstractionPeriod } = require('../../base.presenter.js') | ||
|
||
/** | ||
* Format data for the `/return-log/setup/{sessionId}/period-used` page | ||
* | ||
* @param {module:SessionModel} session - The return log setup session instance | ||
* | ||
* @returns {object} page data needed by the view template | ||
*/ | ||
function go(session) { | ||
const { | ||
id: sessionId, | ||
periodStartDay, | ||
periodStartMonth, | ||
periodEndDay, | ||
periodEndMonth, | ||
periodDateUsedOptions, | ||
returnReference, | ||
periodUsedFromDay, | ||
periodUsedFromMonth, | ||
periodUsedFromYear, | ||
periodUsedToDay, | ||
periodUsedToMonth, | ||
periodUsedToYear | ||
} = session | ||
|
||
return { | ||
abstractionPeriod: formatAbstractionPeriod(periodStartDay, periodStartMonth, periodEndDay, periodEndMonth), | ||
backLink: `/system/return-logs/setup/${sessionId}/single-volume`, | ||
pageTitle: 'What period was used for this volume?', | ||
periodDateUsedOptions: periodDateUsedOptions ?? null, | ||
periodUsedFromDay: periodUsedFromDay ?? null, | ||
periodUsedFromMonth: periodUsedFromMonth ?? null, | ||
periodUsedFromYear: periodUsedFromYear ?? null, | ||
periodUsedToDay: periodUsedToDay ?? null, | ||
periodUsedToMonth: periodUsedToMonth ?? null, | ||
periodUsedToYear: periodUsedToYear ?? null, | ||
returnReference, | ||
sessionId | ||
} | ||
} | ||
|
||
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
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
Oops, something went wrong.