Skip to content

Commit

Permalink
Merge branch 'main' into check-return-logs-change-links
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozzey authored Feb 6, 2025
2 parents 06c1a68 + 26c1fd5 commit ae45cfb
Show file tree
Hide file tree
Showing 35 changed files with 1,857 additions and 68 deletions.
27 changes: 22 additions & 5 deletions app/controllers/notifications-setup.controller.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
'use strict'

const ReturnsPeriodService = require('../services/notifications/setup/returns-period.service.js')
const ReviewService = require('../services/notifications/setup/review.service.js')
const SubmitReturnsPeriodService = require('../services/notifications/setup/submit-returns-period.service.js')
const InitiateSessionService = require('../services/notifications/setup/initiate-session.service.js')

/**
* Controller for /notifications/setup endpoints
* @module NotificationsSetupController
*/

const DownloadRecipientsService = require('../services/notifications/setup/download-recipients.service.js')
const InitiateSessionService = require('../services/notifications/setup/initiate-session.service.js')
const ReturnsPeriodService = require('../services/notifications/setup/returns-period.service.js')
const ReviewService = require('../services/notifications/setup/review.service.js')
const SubmitReturnsPeriodService = require('../services/notifications/setup/submit-returns-period.service.js')

const basePath = 'notifications/setup'

async function downloadRecipients(request, h) {
const {
params: { sessionId }
} = request

const { data, type, filename } = await DownloadRecipientsService.go(sessionId)

return h
.response(data)
.type(type)
.encoding('binary')
.header('Content-Type', type)
.header('Content-Disposition', `attachment; filename="${filename}"`)
}

async function viewReturnsPeriod(request, h) {
const {
params: { sessionId }
Expand Down Expand Up @@ -55,6 +71,7 @@ async function submitReturnsPeriod(request, h) {
}

module.exports = {
downloadRecipients,
viewReturnsPeriod,
viewReview,
setup,
Expand Down
25 changes: 24 additions & 1 deletion app/controllers/return-logs-setup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const InitiateSessionService = require('../services/return-logs/setup/initiate-s
const MeterDetailsService = require('../services/return-logs/setup/meter-details.service.js')
const MeterProvidedService = require('../services/return-logs/setup/meter-provided.service.js')
const NoteService = require('../services/return-logs/setup/note.service.js')
const PeriodUsedService = require('../services/return-logs/setup/period-used.service.js')
const ReceivedService = require('../services/return-logs/setup/received.service.js')
const ReportedService = require('../services/return-logs/setup/reported.service.js')
const SingleVolumeService = require('../services/return-logs/setup/single-volume.service.js')
const SubmissionService = require('../services/return-logs/setup/submission.service.js')
const SubmitMeterDetailsService = require('../services/return-logs/setup/submit-meter-details.service.js')
const SubmitMeterProvidedService = require('../services/return-logs/setup/submit-meter-provided.service.js')
const SubmitNoteService = require('../services/return-logs/setup/submit-note.service.js')
const SubmitPeriodUsedService = require('../services/return-logs/setup/submit-period-used.service.js')
const SubmitReceivedService = require('../services/return-logs/setup/submit-received.service.js')
const SubmitReportedService = require('../services/return-logs/setup/submit-reported.service.js')
const SubmitSingleVolumeService = require('../services/return-logs/setup/submit-single-volume.service.js')
Expand Down Expand Up @@ -66,6 +68,13 @@ async function note(request, h) {
return h.view('return-logs/setup/note.njk', pageData)
}

async function periodUsed(request, h) {
const { sessionId } = request.params
const pageData = await PeriodUsedService.go(sessionId)

return h.view('return-logs/setup/period-used.njk', pageData)
}

async function received(request, h) {
const { sessionId } = request.params
const pageData = await ReceivedService.go(sessionId)
Expand Down Expand Up @@ -148,6 +157,18 @@ async function submitNote(request, h) {
return h.redirect(`/system/return-logs/setup/${sessionId}/check`)
}

async function submitPeriodUsed(request, h) {
const { sessionId } = request.params

const pageData = await SubmitPeriodUsedService.go(sessionId, request.payload)

if (pageData.error) {
return h.view('return-logs/setup/period-used.njk', pageData)
}

return h.redirect(`/system/return-logs/setup/${sessionId}/check`)
}

async function submitReceived(request, h) {
const {
params: { sessionId },
Expand Down Expand Up @@ -196,7 +217,7 @@ async function submitSingleVolume(request, h) {
}

if (pageData.singleVolume === 'no') {
return h.redirect(`/system/return-logs/setup/${sessionId}/check-answers`)
return h.redirect(`/system/return-logs/setup/${sessionId}/check`)
}

return h.redirect(`/system/return-logs/setup/${sessionId}/period-used`)
Expand Down Expand Up @@ -243,6 +264,7 @@ module.exports = {
meterDetails,
meterProvided,
note,
periodUsed,
received,
reported,
setup,
Expand All @@ -251,6 +273,7 @@ module.exports = {
submitMeterDetails,
submitMeterProvided,
submitNote,
submitPeriodUsed,
submitReceived,
submitReported,
submitSingleVolume,
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/return-logs.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

const Boom = require('@hapi/boom')

const SubmitViewReturnLogService = require('../services/return-logs/submit-view-return-log.service.js')

const ViewReturnLogService = require('../services/return-logs/view-return-log.service.js')

async function view(request, h) {
Expand All @@ -18,11 +20,20 @@ async function view(request, h) {

const version = query.version ? Number(query.version) : 0

const pageData = await ViewReturnLogService.go(query.id, version, auth)
const pageData = await ViewReturnLogService.go(query.id, version, auth, request.yar)

return h.view('return-logs/view.njk', pageData)
}

async function submitView(request, h) {
const { id } = request.query

await SubmitViewReturnLogService.go(id, request.yar, request.payload)

return h.redirect(`/system/return-logs?id=${id}`)
}

module.exports = {
submitView,
view
}
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
}
52 changes: 52 additions & 0 deletions app/presenters/return-logs/setup/period-used.presenter.js
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
}
2 changes: 2 additions & 0 deletions app/presenters/return-logs/view-return-log.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function go(returnLog, auth) {
status,
startDate,
twoPartTariff,
underQuery,
versions
} = returnLog

Expand Down Expand Up @@ -74,6 +75,7 @@ function go(returnLog, auth) {
tableTitle: _tableTitle(returnsFrequency, method),
tariff: twoPartTariff ? 'Two-part' : 'Standard',
total: _total(selectedReturnSubmission),
underQuery,
versions: _versions(selectedReturnSubmission, versions, id)
}
}
Expand Down
12 changes: 12 additions & 0 deletions app/routes/notifications-setup.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ const routes = [
}
}
},
{
method: 'GET',
path: basePath + '/{sessionId}/download',
options: {
handler: NotificationsSetupController.downloadRecipients,
auth: {
access: {
scope: ['returns']
}
}
}
},
{
method: 'GET',
path: basePath + '/{sessionId}/returns-period',
Expand Down
24 changes: 24 additions & 0 deletions app/routes/return-logs-setup.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@ const routes = [
}
}
}
},
{
method: 'GET',
path: '/return-logs/setup/{sessionId}/period-used',
options: {
handler: ReturnLogsSetupController.periodUsed,
auth: {
access: {
scope: ['billing']
}
}
}
},
{
method: 'POST',
path: '/return-logs/setup/{sessionId}/period-used',
options: {
handler: ReturnLogsSetupController.submitPeriodUsed,
auth: {
access: {
scope: ['billing']
}
}
}
}
]

Expand Down
7 changes: 7 additions & 0 deletions app/routes/return-logs.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const routes = [
options: {
handler: ReturnLogsController.view
}
},
{
method: 'POST',
path: '/return-logs',
options: {
handler: ReturnLogsController.submitView
}
}
]

Expand Down
Loading

0 comments on commit ae45cfb

Please sign in to comment.