-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
f9eaa44
52f0bd4
9fce8fd
5235575
961cb7b
45f533f
065cf2c
ac75646
c1bb9c2
7ba7225
978f89c
5710b16
12fff05
dd3c341
6e508e9
781a196
e9bf383
be26c60
cb5aa94
73ead81
b151c6d
4266a14
bbbf057
d961f31
5d71802
47d6d19
9a09f87
24f44e0
27ce521
4d892d0
370a342
d8a5cdb
368e376
f701032
db46285
a23a058
2f90bc2
a8a99a0
29c3ac0
0f0f121
6af1273
389a927
47fd447
cdd973f
3107151
c542281
7dde0a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -38,6 +38,36 @@ const routes = [ | |||||||
} | ||||||||
} | ||||||||
} | ||||||||
}, | ||||||||
{ | ||||||||
method: 'GET', | ||||||||
path: '/return-logs/setup/{sessionId}/start', | ||||||||
options: { | ||||||||
handler: ReturnLogsSetupController.start, | ||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
auth: { | ||||||||
access: { | ||||||||
scope: ['billing'] | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
] | ||||||||
|
||||||||
|
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 | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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.