diff --git a/app/controllers/licences.controller.js b/app/controllers/licences.controller.js index f84bda4e47..3391c9889c 100644 --- a/app/controllers/licences.controller.js +++ b/app/controllers/licences.controller.js @@ -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 } diff --git a/app/controllers/return-requirements.controller.js b/app/controllers/return-requirements.controller.js new file mode 100644 index 0000000000..6e6228133b --- /dev/null +++ b/app/controllers/return-requirements.controller.js @@ -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 +} diff --git a/app/plugins/router.plugin.js b/app/plugins/router.plugin.js index 24577d70b9..d218cf1e6e 100644 --- a/app/plugins/router.plugin.js +++ b/app/plugins/router.plugin.js @@ -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') @@ -36,6 +37,7 @@ const routes = [ ...BillingAccountRoutes, ...LicenceRoutes, ...JobRoutes, + ...ReturnRequirementRoutes, ...CheckRoutes, ...DataRoutes ] diff --git a/app/routes/licence.routes.js b/app/routes/licence.routes.js index 0e722f76ad..dc2dd3c6c1 100644 --- a/app/routes/licence.routes.js +++ b/app/routes/licence.routes.js @@ -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' - } } ] diff --git a/app/routes/return-requirement.routes.js b/app/routes/return-requirement.routes.js new file mode 100644 index 0000000000..2339d56b83 --- /dev/null +++ b/app/routes/return-requirement.routes.js @@ -0,0 +1,189 @@ +'use strict' + +const ReturnRequirementsController = require('../controllers/return-requirements.controller.js') + +const routes = [ + { + method: 'GET', + path: '/return-requirements/{sessionId}/select-return-start-date', + handler: ReturnRequirementsController.selectReturnStartDate, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Select the start date of the return' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/select-return-start-date', + handler: ReturnRequirementsController.saveReturnStartDate, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Select the start date of the return' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/reason', + handler: ReturnRequirementsController.reasonNewRequirements, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Reason page' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/reason', + handler: ReturnRequirementsController.saveReasonNewRequirements, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Reason page' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/returns-how-do-you-want', + handler: ReturnRequirementsController.returnsHowDoYouWant, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Returns required - create How do you want to set up the requirements' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/returns-how-do-you-want', + handler: ReturnRequirementsController.saveReturnsHowDoYouWant, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Returns required - create How do you want to set up the requirements' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/returns-check-your-answers', + handler: ReturnRequirementsController.returnsCheckYourAnswers, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Returns check your answers page' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/returns-check-your-answers', + handler: ReturnRequirementsController.saveReturnsCheckYourAnswers, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Returns check your answers page' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/requirements-approved', + handler: ReturnRequirementsController.requirementsApproved, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Returns requirements approved' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/no-returns-required', + handler: ReturnRequirementsController.noReturnsRequired, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Show no returns required page' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/no-returns-required', + handler: ReturnRequirementsController.saveNoReturnsRequired, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Save no returns required option' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/no-return-check-your-answers', + handler: ReturnRequirementsController.noReturnsCheckYourAnswers, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'No return check your answers page' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/no-return-check-your-answers', + handler: ReturnRequirementsController.saveNoReturnsCheckYourAnswers, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'No return check your answers page' + } + }, { + method: 'GET', + path: '/return-requirements/{sessionId}/add-a-note', + handler: ReturnRequirementsController.addANote, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Returns add a note page' + } + }, { + method: 'POST', + path: '/return-requirements/{sessionId}/add-a-note', + handler: ReturnRequirementsController.saveNote, + options: { + auth: { + access: { + scope: ['billing'] + } + }, + description: 'Save note' + } + } +] + +module.exports = routes diff --git a/app/views/return-requirements/add-a-note.njk b/app/views/return-requirements/add-a-note.njk index 7d7958a95e..3e2dea4d75 100644 --- a/app/views/return-requirements/add-a-note.njk +++ b/app/views/return-requirements/add-a-note.njk @@ -19,7 +19,9 @@