Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What do you want to do with this return? #1570

Merged
merged 84 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
f9eaa44
How would you like to edit this return
Jozzey Dec 16, 2024
52f0bd4
Merge branch 'main' into how-to-edit-return
Jozzey Dec 16, 2024
9fce8fd
Create route and controller
Jozzey Dec 17, 2024
5235575
Initial page setup
Jozzey Dec 27, 2024
961cb7b
Merge branch 'main' into how-to-edit-return
Jozzey Dec 27, 2024
45f533f
Create service to fetch the data
Jozzey Dec 27, 2024
065cf2c
Update routes to use a querystring
Jozzey Dec 30, 2024
ac75646
Sort out backlink
Jozzey Dec 30, 2024
c1bb9c2
Create presenter
Jozzey Dec 30, 2024
7ba7225
Add POST route
Jozzey Dec 30, 2024
978f89c
Add validation
Jozzey Dec 30, 2024
5710b16
Tidy up validation error
Jozzey Dec 30, 2024
12fff05
Make some tweaks to the controller
Jozzey Dec 31, 2024
dd3c341
Merge remote-tracking branch 'origin/main' into how-to-edit-return
Jozzey Dec 31, 2024
6e508e9
Refactor following PR https://github.com/DEFRA/water-abstraction-syst…
Jozzey Dec 31, 2024
781a196
Make it work following merge
Jozzey Dec 31, 2024
e9bf383
Create submit service
Jozzey Dec 31, 2024
be26c60
Persist selected option
Jozzey Dec 31, 2024
cb5aa94
Make prettier
Jozzey Dec 31, 2024
73ead81
Refactor to minimise merge issues
Jozzey Jan 6, 2025
b151c6d
Merge remote-tracking branch 'origin/main' into how-to-edit-return
Jozzey Jan 6, 2025
4266a14
Add feature flag `ENABLE_SYSTEM_RETURNS_VIEW`
Jozzey Jan 7, 2025
bbbf057
Update view with new layout
Jozzey Jan 7, 2025
d961f31
Rename a load of things following changes to page
Jozzey Jan 7, 2025
5d71802
Update controller test
Jozzey Jan 7, 2025
47d6d19
Add return log status to initiate session data
Jozzey Jan 7, 2025
9a09f87
Add received date to initiate session data
Jozzey Jan 7, 2025
24f44e0
Add feature flag to link
Jozzey Jan 7, 2025
27ce521
Make record receipt option conditional
Jozzey Jan 7, 2025
4d892d0
Update radio button values
Jozzey Jan 8, 2025
370a342
Fix filename
Jozzey Jan 8, 2025
d8a5cdb
Update redirect route for submit
Jozzey Jan 8, 2025
368e376
Update links
Jozzey Jan 8, 2025
f701032
Add due date to session data
Jozzey Jan 8, 2025
db46285
Add return log status tag to view
Jozzey Jan 8, 2025
a23a058
Sort out how the return log status is displayed
Jozzey Jan 8, 2025
2f90bc2
Fix status tag
Jozzey Jan 8, 2025
a8a99a0
Tidy up view
Jozzey Jan 8, 2025
29c3ac0
Merge branch 'main' into how-to-edit-return
Jozzey Jan 8, 2025
0f0f121
Remove view licence link
Jozzey Jan 9, 2025
6af1273
Create controller unit tests
Jozzey Jan 9, 2025
389a927
Create presenter tests
Jozzey Jan 10, 2025
47fd447
Create start service tests
Jozzey Jan 10, 2025
cdd973f
Create submit start tests
Jozzey Jan 10, 2025
3107151
Stub new feature flag in existing test
Jozzey Jan 10, 2025
c542281
Update to minimise merge hell :crossed_fingers:
Jozzey Jan 10, 2025
7dde0a2
Merge remote-tracking branch 'origin/main' into how-to-edit-return
Jozzey Jan 10, 2025
57b5281
Sort out route issue as per review
Jozzey Jan 13, 2025
bb8285b
Add separate test for `overdue` status as per review comment
Jozzey Jan 13, 2025
957c660
Add a comment to test
Jozzey Jan 13, 2025
96d0aaa
Create validator for submit start service as per review comment
Jozzey Jan 13, 2025
f3dcc64
Create validator unit tests
Jozzey Jan 13, 2025
1cc82aa
Merge branch 'main' into how-to-edit-return
Jozzey Jan 13, 2025
46e7def
Tiny tweak
Jozzey Jan 13, 2025
a14d845
Fix unit test
Jozzey Jan 13, 2025
15c7ad9
Fix another test
Jozzey Jan 13, 2025
d3153a2
Fix another test
Jozzey Jan 13, 2025
56154b4
Remove duplicated tests
Jozzey Jan 13, 2025
fda29fe
Update comment
Jozzey Jan 13, 2025
b391184
Update comment
Jozzey Jan 13, 2025
6bbb4d7
Update comment
Jozzey Jan 13, 2025
46f49d6
Update comment
Jozzey Jan 13, 2025
6a71735
Update comment
Jozzey Jan 13, 2025
1195c35
Update comment
Jozzey Jan 13, 2025
78944a2
Update comment
Jozzey Jan 13, 2025
3d37aa1
Update comment
Jozzey Jan 13, 2025
6d8e775
Update comment
Jozzey Jan 13, 2025
4a4fc6e
Update comment
Jozzey Jan 13, 2025
33f0181
Move activeNavBar into service
Jozzey Jan 14, 2025
4e80ee4
Move `activeNavBar` into submit service
Jozzey Jan 14, 2025
f500b53
Rename `whatToDo` to `journey`
Jozzey Jan 14, 2025
e95f791
Make values kebab-case
Jozzey Jan 14, 2025
ee51385
Remove .only
Jozzey Jan 14, 2025
b1ad832
Add missing `afterEach` to unit test
Jozzey Jan 15, 2025
4c85010
Update return log link in 2pt review screens
Jozzey Jan 15, 2025
618faf3
Rename back link "Go back to licence"
Jozzey Jan 15, 2025
5fedd0d
Remove `returnLogId` as not needed
Jozzey Jan 15, 2025
8046c7f
Rename back link "Go back to summary"
Jozzey Jan 15, 2025
30b2357
Merge remote-tracking branch 'origin/main' into how-to-edit-return
Jozzey Jan 15, 2025
08181b9
Tidy up controller to meet new convention
Jozzey Jan 15, 2025
38b9332
Remove unnecessary status
Jozzey Jan 15, 2025
e02b109
Reorder unit tests after the merge messed it up
Jozzey Jan 15, 2025
4a92d47
Update view as per review comment
Jozzey Jan 15, 2025
1c0d5d4
Update presenter comment
Jozzey Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ ENABLE_TWO_PART_TARIFF_SUPPLEMENTARY=false
ENABLE_MONITORING_STATIONS_VIEW=true
ENABLE_LICENCE_PURPOSES_VIEW=true
ENABLE_LICENCE_POINTS_VIEW=true
ENABLE_SYSTEM_RETURNS_VIEW=true
29 changes: 26 additions & 3 deletions app/controllers/return-logs-setup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,39 @@
const InitiateSessionService = require('../services/return-logs/setup/initiate-session.service.js')
const ReceivedService = require('../services/return-logs/setup/received.service.js')
const ReportedService = require('../services/return-logs/setup/reported.service.js')
const StartService = require('../services/return-logs/setup/start.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 SubmitStartService = require('../services/return-logs/setup/submit-start.service.js')
const SubmitUnitsService = require('../services/return-logs/setup/submit-units.service.js')
const UnitsService = require('../services/return-logs/setup/units.service.js')

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

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

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

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

async function setup(request, h) {
const { returnLogId } = request.query
const session = await InitiateSessionService.go(returnLogId)

return h.redirect(`/system/return-logs/setup/${session.id}/how-to-edit`)
return h.redirect(`/system/return-logs/setup/${session.id}/start`)
}

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

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

async function submitReceived(request, h) {
Expand Down Expand Up @@ -64,6 +73,18 @@ async function submitReported(request, h) {
return h.redirect(`/system/return-logs/setup/${sessionId}/units`)
}

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

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

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

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

async function submitUnits(request, h) {
const {
params: { sessionId },
Expand All @@ -90,8 +111,10 @@ module.exports = {
received,
reported,
setup,
start,
submitReceived,
submitReported,
submitStart,
submitUnits,
units
}
7 changes: 6 additions & 1 deletion app/presenters/bill-runs/review/base-review.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Big = require('big.js')

const { formatLongDate } = require('../../base.presenter.js')
const DetermineAbstractionPeriodService = require('../../../services/bill-runs/determine-abstraction-periods.service.js')
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')

/**
* Calculates the total allocated volume across all review change elements
Expand Down Expand Up @@ -31,7 +32,11 @@ function determineReturnLink(reviewReturn) {
const { returnId, returnStatus } = reviewReturn

if (['due', 'received'].includes(returnStatus)) {
return `/return/internal?returnId=${returnId}`
if (FeatureFlagsConfig.enableSystemReturnsView) {
return `/system/return-logs/setup?returnLogId=${returnId}`
} else {
return `/return/internal?returnId=${returnId}`
}
}

return `/returns/return?id=${returnId}`
Expand Down
7 changes: 6 additions & 1 deletion app/presenters/licences/view-licence-returns.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @module ViewLicenceReturnsPresenter
*/

const FeatureFlagsConfig = require('../../../config/feature-flags.config.js')
const { formatLongDate } = require('../base.presenter.js')

/**
Expand Down Expand Up @@ -34,7 +35,11 @@ function _link(status, returnLogId, canManageReturns) {
}

if (canManageReturns) {
return `/return/internal?returnId=${returnLogId}`
if (FeatureFlagsConfig.enableSystemReturnsView) {
return `/system/return-logs/setup?returnLogId=${returnLogId}`
} else {
return `/return/internal?returnId=${returnLogId}`
}
}

return null
Expand Down
77 changes: 77 additions & 0 deletions app/presenters/return-logs/setup/start.presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict'

/**
* Formats the data ready for presenting in the `/return-logs/setup/{sessionId}/start` page
* @module StartPresenter
*/

const { formatAbstractionPeriod, formatLongDate } = require('../../base.presenter.js')

/**
* Formats the data ready for presenting in the `/return-logs/setup/{sessionId}/start` page
*
* @param {module:SessionModel} session - The session instance to format
*
* @returns {object} page data needed for the `/return-logs/setup/{sessionId}/start` page
*/
function go(session) {
const {
dueDate,
endDate,
journey,
licenceId,
licenceRef,
periodStartDay,
periodStartMonth,
periodEndDay,
periodEndMonth,
purposes,
receivedDate,
returnReference,
siteDescription,
startDate,
status,
twoPartTariff
} = session

return {
abstractionPeriod: `From ${formatAbstractionPeriod(
Jozzey marked this conversation as resolved.
Show resolved Hide resolved
periodStartDay,
periodStartMonth,
periodEndDay,
periodEndMonth
)}`,
displayRecordReceipt: receivedDate === null,
journey: journey ?? null,
licenceId,
Jozzey marked this conversation as resolved.
Show resolved Hide resolved
licenceRef,
pageTitle: 'Abstraction return',
Jozzey marked this conversation as resolved.
Show resolved Hide resolved
purposes,
returnsPeriod: `From ${formatLongDate(new Date(startDate))} to ${formatLongDate(new Date(endDate))}`,
returnReference,
siteDescription,
status: _status(status, dueDate),
tariffType: twoPartTariff ? 'Two part tariff' : 'Standard tariff'
}
}

function _status(status, dueDate) {
if (status === 'due') {
// Work out if the return is overdue (status is still 'due' and it is past the due date)
const today = new Date()
// Reset today's time to midnight to ensure only the date is compared
today.setHours(0, 0, 0, 0)

if (new Date(dueDate) < today) {
return 'overdue'
}
}

// For all other cases we can just return the status and the return-status-tag macro will know how to display it
// return status
return status
}

module.exports = {
go
}
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 @@ -63,6 +63,30 @@ const routes = [
}
}
},
{
method: 'GET',
path: '/return-logs/setup/{sessionId}/start',
options: {
handler: ReturnLogsSetupController.start,
auth: {
access: {
scope: ['billing']
}
}
}
},
{
method: 'POST',
path: '/return-logs/setup/{sessionId}/start',
options: {
handler: ReturnLogsSetupController.submitStart,
auth: {
access: {
scope: ['billing']
}
}
}
},
{
method: 'GET',
path: '/return-logs/setup/{sessionId}/units',
Expand Down
3 changes: 3 additions & 0 deletions app/services/return-logs/setup/initiate-session.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ async function _fetchReturnLog(returnLogId) {
'returnLogs.id as returnLogId',
'returnLogs.startDate',
'returnLogs.endDate',
'returnLogs.receivedDate',
'returnLogs.returnReference',
'returnLogs.dueDate',
'returnLogs.status',
'returnLogs.underQuery',
ref('returnLogs.metadata:nald.periodStartDay').castInt().as('periodStartDay'),
ref('returnLogs.metadata:nald.periodStartMonth').castInt().as('periodStartMonth'),
Expand Down
31 changes: 31 additions & 0 deletions app/services/return-logs/setup/start.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

/**
* Orchestrates fetching and presenting the data needed for the `/return-logs/setup/{sessionId}/start` page
* @module StartService
*/

const SessionModel = require('../../../models/session.model.js')
const StartPresenter = require('../../../presenters/return-logs/setup/start.presenter.js')

/**
* Orchestrates fetching and presenting the data needed for the `/return-logs/setup/{sessionId}/start` page
*
* @param {string} sessionId - The UUID of the current session
*
* @returns {Promise<object>} page data needed by the view template
*/
async function go(sessionId) {
const session = await SessionModel.query().findById(sessionId)

const formattedData = StartPresenter.go(session)

return {
activeNavBar: 'search',
...formattedData
}
}

module.exports = {
go
}
62 changes: 62 additions & 0 deletions app/services/return-logs/setup/submit-start.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'

/**
* Handles the user submission for the `/return-logs/setup/{sessionId}/start` page
* @module SubmitStartService
*/

const SessionModel = require('../../../models/session.model.js')
const StartPresenter = require('../../../presenters/return-logs/setup/start.presenter.js')
const StartValidator = require('../../../validators/return-logs/setup/start.validator.js')

/**
* Handles the user submission for the `/return-logs/setup/{sessionId}/start` page
*
* @param {string} sessionId - The UUID of the current session
* @param {object} payload - The submitted form data
*
* @returns {Promise<object>} An object with a `journey:` property if there are no errors else the page data for
* the abstraction return page including the validation error details
*/
async function go(sessionId, payload) {
const session = await SessionModel.query().findById(sessionId)
const validationResult = _validate(payload)

if (!validationResult) {
await _save(session, payload)

return {}
}

const formattedData = StartPresenter.go(session)

return {
activeNavBar: 'search',
error: validationResult,
...formattedData
}
}

async function _save(session, payload) {
session.journey = payload.journey

return session.$update()
}

function _validate(payload) {
const validation = StartValidator.go(payload)

if (!validation.error) {
return null
}

const { message } = validation.error.details[0]

return {
text: message
}
}

module.exports = {
go
}
39 changes: 39 additions & 0 deletions app/validators/return-logs/setup/start.validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

/**
* Validates data submitted for the `/return-logs/setup/{sessionId}/start` page
* @module StartValidator
*/

const Joi = require('joi')

const VALID_VALUES = ['enter-return', 'nil-return', 'record-receipt']

/**
* Validates data submitted for the `/return-logs/setup/{sessionId}/start` page
*
* @param {object} payload - The payload from the request to be validated
*
* @returns {object} the result from calling Joi's schema.validate(). It will be an object with a `value:` property. If
* any errors are found the `error:` property will also exist detailing what the issues were
*/
function go(payload) {
const errorMessage = 'Select what you want to do with this return'

const schema = Joi.object({
journey: Joi.string()
.required()
.valid(...VALID_VALUES)
.messages({
'any.required': errorMessage,
'any.only': errorMessage,
'string.empty': errorMessage
})
})

return schema.validate(payload, { abortEarly: false })
}

module.exports = {
go
}
Loading
Loading