-
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.
Move rtn req. routes and session handling (#597)
Having discussed and agreed a way forward for handling temporary sessions in our code base this demonstrates how we can create the initial session, then retrieve it in subsequent requests. The other thing it does is break the dependence on the return requirement journey sitting under `/licences`. `/licences` is still the gateway to the journey, creating the temporary session for tracking the journey. But it then redirects away so `/return-requirements` can take over. The benefit of this is without any additional controls, we have a way of 'clearing' the session. Essentially, the user simply has to leave the journey and start again and the session is cleared. But whilst in the journey the user can go forwards and backwards throughout and each page can validly assume `sessionId` refers to an existing record. --------- Co-authored-by: Alan Cruikshanks <[email protected]>
- Loading branch information
Showing
14 changed files
with
645 additions
and
232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
'use strict' | ||
|
||
/** | ||
* Controller for /return-requirement endpoints | ||
* @module ReturnRequirementsController | ||
*/ | ||
|
||
const SessionModel = require('../models/session.model.js') | ||
|
||
async function selectReturnStartDate (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/select-return-start-date.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveReturnStartDate (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.redirect(`/system/return-requirements/${session.id}/reason`) | ||
} | ||
|
||
async function reasonNewRequirements (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/reason.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveReasonNewRequirements (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.redirect(`/system/return-requirements/${session.id}/returns-how-do-you-want`) | ||
} | ||
|
||
async function returnsHowDoYouWant (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/returns-how-do-you-want.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveReturnsHowDoYouWant (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.redirect(`/system/return-requirements/${session.id}/returns-check-your-answers`) | ||
} | ||
|
||
async function returnsCheckYourAnswers (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/returns-check-your-answers.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveReturnsCheckYourAnswers (request, h) { | ||
return h.redirect('/system/return-requirements/requirements-approved') | ||
} | ||
|
||
async function requirementsApproved (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/requirements-approved.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function noReturnsRequired (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/no-returns-required.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveNoReturnsRequired (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.redirect(`/system/return-requirements/${session.id}/no-returns-check-your-answers`) | ||
} | ||
|
||
async function noReturnsCheckYourAnswers (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/no-return-check-your-answers.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveNoReturnsCheckYourAnswers (request, h) { | ||
return h.redirect('/system/return-requirements/requirements-approved') | ||
} | ||
|
||
async function addANote (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
return h.view('return-requirements/add-a-note.njk', { | ||
activeNavBar: 'search', | ||
...session | ||
}) | ||
} | ||
|
||
async function saveNote (request, h) { | ||
const { sessionId } = request.params | ||
|
||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
const { id } = session | ||
|
||
return h.redirect(`/system/return-requirements/${id}/returns-check-your-answers`) | ||
} | ||
|
||
module.exports = { | ||
addANote, | ||
noReturnsCheckYourAnswers, | ||
noReturnsRequired, | ||
reasonNewRequirements, | ||
requirementsApproved, | ||
returnsCheckYourAnswers, | ||
returnsHowDoYouWant, | ||
saveNoReturnsCheckYourAnswers, | ||
saveNoReturnsRequired, | ||
saveNote, | ||
saveReasonNewRequirements, | ||
saveReturnsCheckYourAnswers, | ||
saveReturnsHowDoYouWant, | ||
saveReturnStartDate, | ||
selectReturnStartDate | ||
} |
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.