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

Move rtn req. routes and session handling #597

Merged
merged 8 commits into from
Dec 19, 2023
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

sonarcloud is complaining about this function being the same as saveNote

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put in a small change to make it pass.

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
}
1 change: 1 addition & 0 deletions app/plugins/auth.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const AuthPlugin = {
},
redirectTo: '/signin',
validate: async (_request, session) => {
console.log('🚀 ~ file: auth.plugin.js:50 ~ validate: ~ session:', session)
Copy link
Member

Choose a reason for hiding this comment

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

Doh! Something I should have spotted the first time around.

Suggested change
console.log('🚀 ~ file: auth.plugin.js:50 ~ validate: ~ session:', session)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

weird that it's showing up on my PR.. it's not something I added. but i've removed it now

return AuthService.go(session.userId)
}
})
Expand Down
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
Loading