diff --git a/app/controllers/check.controller.js b/app/controllers/check.controller.js index 1420fb0ad8..f168a7914e 100644 --- a/app/controllers/check.controller.js +++ b/app/controllers/check.controller.js @@ -5,9 +5,36 @@ * @module CheckController */ +const DetermineSupplementaryBillingFlagsService = require('../services/import/determine-supplementary-billing-flags.service.js') const ProcessLicenceReturnLogsService = require('../services/jobs/return-logs/process-licence-return-logs.service.js') -const redirectStatusCode = 204 +const NO_CONTENT_STATUS_CODE = 204 + +/** + * A test end point for the licence supplementary billing flags process + * + * This endpoint takes a licenceId and an expired, lapsed and revoked date. It passes this onto the + * `DetermineSupplementaryBillingFlagsService` to test if it correctly flags the licence for supplementary billing. This + * normally happens during the licence import process. + * + * @param request - the hapi request object + * @param h - the hapi response object + * + * @returns {Promise} - A promise that resolves to an HTTP response object with a 204 status code + */ +async function flagForBilling (request, h) { + const { licenceId, expiredDate, lapsedDate, revokedDate } = request.payload + + const transformedLicence = { + expiredDate, + lapsedDate, + revokedDate + } + + await DetermineSupplementaryBillingFlagsService.go(transformedLicence, licenceId) + + return h.response().code(NO_CONTENT_STATUS_CODE) +} /** * A test end point to create return logs for a given licence reference @@ -28,9 +55,10 @@ async function returnLogsForLicence (_request, h) { ProcessLicenceReturnLogsService.go(licenceReference) - return h.response().code(redirectStatusCode) + return h.response().code(NO_CONTENT_STATUS_CODE) } module.exports = { + flagForBilling, returnLogsForLicence } diff --git a/app/routes/check.routes.js b/app/routes/check.routes.js index 6aa6161519..599b123825 100644 --- a/app/routes/check.routes.js +++ b/app/routes/check.routes.js @@ -3,6 +3,21 @@ const CheckController = require('../controllers/check.controller.js') const routes = [ + { + method: 'POST', + path: '/check/flag-for-billing', + options: { + handler: CheckController.flagForBilling, + app: { + excludeFromProd: true, + plainOutput: true + }, + auth: false, + plugins: { + crumb: false + } + } + }, { method: 'POST', path: '/check/licence-return-logs',