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

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 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
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
30 changes: 28 additions & 2 deletions app/controllers/return-logs-setup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

const InitiateSessionService = require('../services/return-logs/setup/initiate-session.service.js')
const ReceivedService = require('../services/return-logs/setup/received.service.js')
const StartService = require('../services/return-logs/setup/start.service.js')
const SubmitReceivedService = require('../services/return-logs/setup/submit-received.service.js')
const SubmitStartService = require('../services/return-logs/setup/submit-start.service.js')

async function received(request, h) {
const { sessionId } = request.params
Expand All @@ -20,7 +22,14 @@ 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', { activeNavBar: 'search', ...pageData })
}

async function submitReceived(request, h) {
Expand All @@ -38,8 +47,25 @@ async function submitReceived(request, h) {
return h.redirect(`/system/return-logs/setup/${sessionId}/reported`)
}

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', {
activeNavBar: 'search',
...pageData
})
}

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

module.exports = {
received,
setup,
submitReceived
start,
submitReceived,
submitStart
}
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
84 changes: 84 additions & 0 deletions app/presenters/return-logs/setup/start.presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use strict'

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

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

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

return {
abstractionPeriod: `From ${formatAbstractionPeriod(
periodStartDay,
periodStartMonth,
periodEndDay,
periodEndMonth
)}`,
displayRecordReceipt: receivedDate === null,
licenceId,
licenceRef,
pageTitle: 'Abstraction return',
purposes,
returnLogId,
returnsPeriod: `From ${formatLongDate(new Date(startDate))} to ${formatLongDate(new Date(endDate))}`,
returnReference,
selectedOption: whatToDo ?? whatToDo,
siteDescription,
status: _status(status, dueDate),
tariffType: twoPartTariff ? 'Two part tariff' : 'Standard tariff'
}
}

function _status(status, dueDate) {
// If the return is completed we are required to display it as 'complete'. This also takes priority over the other
// statues
if (status === 'completed') {
return 'complete'
}

// Work out if the return is overdue (status is still 'due' and it is past the due date)
const today = new Date()

// The due date held in the record is date-only. If we compared it against 'today' without this step any return due
// 'today' would be flagged as overdue when it is still due (just!)
today.setHours(0, 0, 0, 0)

if (status === 'due' && 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
}

module.exports = {
go
}
30 changes: 30 additions & 0 deletions app/routes/return-logs-setup.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ const routes = [
}
}
}
},
{
method: 'GET',
path: '/return-logs/setup/{sessionId}/start',
options: {
handler: ReturnLogsSetupController.start,
app: {
plainOutput: true
},
Comment on lines +47 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an API only endpoint so should not have this config.

Suggested change
app: {
plainOutput: true
},

auth: {
access: {
scope: ['billing']
}
}
}
},
{
method: 'POST',
path: '/return-logs/setup/{sessionId}/start',
options: {
handler: ReturnLogsSetupController.submitStart,
app: {
plainOutput: true
},
Comment on lines +62 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
app: {
plainOutput: true
},

auth: {
access: {
scope: ['billing']
}
}
}
}
]

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
26 changes: 26 additions & 0 deletions app/services/return-logs/setup/start.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

/**
* Orchestrates fetching and presenting the data needed for the `/return-log-edit/{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-log-edit/{sessionId}/start` page
*
* @param {string} sessionId - The UUID for setup bill run session record
*
* @returns {Promise<object>} page data needed by the view template
*/
async function go(sessionId) {
const session = await SessionModel.query().findById(sessionId)

return StartPresenter.go(session)
}

module.exports = {
go
}
57 changes: 57 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,57 @@
'use strict'

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

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

/**
* Handles the user submission for the `/return-log-edit/{sessionId}/start` page
*
* @param {string} sessionId - The UUID for setup bill run session record
* @param {object} payload - The submitted form data
*
* @returns {Promise<object>} An object with a `whatToDo:` 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 { whatToDo } = payload
const validationResult = _validate(whatToDo)

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

return { whatToDo }
}

const formattedData = StartPresenter.go(session)

return {
error: validationResult,
...formattedData
}
}

async function _save(session, whatToDo) {
const currentData = session

currentData.whatToDo = whatToDo

return session.$query().patch({ data: currentData })
}

function _validate(whatToDo) {
if (!whatToDo) {
return { text: 'Select what you want to do with this return' }
}

return null
}
Comment on lines +47 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate this is all that is needed to validate the entry. But it breaks the pattern we have used for all our other pages.

We need a proper Joi-based validator for this, of which there are plenty you can crib from.


module.exports = {
go
}
Loading
Loading