Skip to content

Commit

Permalink
Move rtn req. routes and session handling (#597)
Browse files Browse the repository at this point in the history
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
2 people authored and Demwunz committed Dec 20, 2023
1 parent acc58d0 commit 7deed4a
Show file tree
Hide file tree
Showing 14 changed files with 645 additions and 232 deletions.
64 changes: 10 additions & 54 deletions app/controllers/licences.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,21 @@
* @module LicencesController
*/

async function noReturnsRequired (request, h) {
const { id } = request.params

return h.view('return-requirements/no-returns-required.njk', {
activeNavBar: 'search',
licenceId: id
})
}

async function selectReturnStartDate (request, h) {
const { id } = request.params

return h.view('return-requirements/select-return-start-date.njk', {
activeNavBar: 'search',
licenceId: id
})
}

async function requirementsApproved (request, h) {
const { id } = request.params
const SessionModel = require('../models/session.model.js')

return h.view('return-requirements/requirements-approved.njk', {
activeNavBar: 'search',
licenceId: id
})
}

async function noReturnsCheckYourAnswers (request, h) {
const { id } = request.params

return h.view('return-requirements/no-return-check-your-answers.njk', {
activeNavBar: 'search',
licenceId: id
})
}

async function returnsCheckYourAnswers (request, h) {
async function noReturnsRequired (request, h) {
const { id } = request.params

return h.view('return-requirements/returns-check-your-answers.njk', {
activeNavBar: 'search',
licenceId: id
})
}

async function addANote (request, h) {
const { id } = request.params
const data = { licenceId: id }
const session = await SessionModel.query()
.insert({
data
})
.returning('*')

return h.view('return-requirements/add-a-note.njk', {
activeNavBar: 'search',
licenceId: id
})
return h.redirect(`/system/return-requirements/${session.id}/select-return-start-date`)
}

module.exports = {
addANote,
noReturnsCheckYourAnswers,
noReturnsRequired,
requirementsApproved,
returnsCheckYourAnswers,
selectReturnStartDate
noReturnsRequired
}
164 changes: 164 additions & 0 deletions app/controllers/return-requirements.controller.js
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
}
2 changes: 2 additions & 0 deletions app/plugins/router.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const FilterRoutesService = require('../services/plugins/filter-routes.service.j
const HealthRoutes = require('../routes/health.routes.js')
const JobRoutes = require('../routes/jobs.routes.js')
const LicenceRoutes = require('../routes/licence.routes.js')
const ReturnRequirementRoutes = require('../routes/return-requirement.routes.js')
const RootRoutes = require('../routes/root.routes.js')

const AirbrakeConfig = require('../../config/airbrake.config.js')
Expand All @@ -36,6 +37,7 @@ const routes = [
...BillingAccountRoutes,
...LicenceRoutes,
...JobRoutes,
...ReturnRequirementRoutes,
...CheckRoutes,
...DataRoutes
]
Expand Down
60 changes: 0 additions & 60 deletions app/routes/licence.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,6 @@ const routes = [
},
description: 'Review two-part tariff match and allocation results'
}
}, {
method: 'GET',
path: '/licences/{id}/select-return-start-date',
handler: LicencesController.selectReturnStartDate,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'Select the start date of the return'
}
}, {
method: 'GET',
path: '/licences/{id}/no-return-check-your-answers',
handler: LicencesController.noReturnsCheckYourAnswers,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'No return check your answers page'
}
}, {
method: 'GET',
path: '/licences/{id}/requirements-approved',
handler: LicencesController.requirementsApproved,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'Returns requirements approved'
}
}, {
method: 'GET',
path: '/licences/{id}/returns-check-your-answers',
handler: LicencesController.returnsCheckYourAnswers,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'Returns check your answers page'
}
}, {
method: 'GET',
path: '/licences/{id}/add-a-note',
handler: LicencesController.addANote,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'Returns add a note page'
}
}
]

Expand Down
Loading

0 comments on commit 7deed4a

Please sign in to comment.