From ee27692d4f537122697cccc4436b567f8ba2457c Mon Sep 17 00:00:00 2001 From: Ulysses Alvarez Date: Fri, 10 Jan 2025 17:39:25 +0000 Subject: [PATCH] activated page not found route, ni poscode entry in uk location. --- src/server/location-not-found/controller.js | 46 ++++++++++--------- .../location-not-found/cy/controller.js | 45 ++++++++++-------- src/server/location-not-found/cy/index.js | 14 +++--- src/server/location-not-found/index.js | 14 +++--- src/server/locations/helpers/fetch-data.js | 2 +- src/server/locations/middleware.js | 12 +---- src/server/router.js | 4 ++ 7 files changed, 71 insertions(+), 66 deletions(-) diff --git a/src/server/location-not-found/controller.js b/src/server/location-not-found/controller.js index 350482dc..63c46267 100644 --- a/src/server/location-not-found/controller.js +++ b/src/server/location-not-found/controller.js @@ -1,26 +1,30 @@ -const searchLocationController = { +import { LOCATION_NOT_FOUND } from '~/src/server/data/constants' +import { english } from '~/src/server/data/en/en.js' + +const locationNotFoundController = { handler: (request, h) => { - const { query } = request - return h.view('location-not-found/index', { - pageTitle: 'Check air quality - GOV.UK', - heading: 'Check air quality', - page: 'location', - serviceName: 'Check air quality', - searchParams: { - label: { - text: 'Where do you want to check?', - classes: 'govuk-label--l govuk-!-margin-bottom-6', - isPageHeading: true - }, - hint: { - text: 'Enter a location or postcode' - }, - id: 'location', - name: 'location' - }, - lang: query.lang + const locationData = request.yar.get('locationDataNotFound') || [] + const { locationNameOrPostcode, lang } = locationData + const { + notFoundLocation, + home, + footerTxt, + phaseBanner, + backlink, + cookieBanner + } = english + return h.view(LOCATION_NOT_FOUND, { + userLocation: locationNameOrPostcode, + serviceName: notFoundLocation.heading, + paragraph: notFoundLocation.paragraphs, + pageTitle: `${notFoundLocation.paragraphs.a} ${locationNameOrPostcode} - ${home.pageTitle}`, + footerTxt, + phaseBanner, + backlink, + cookieBanner, + lang }) } } -export { searchLocationController } +export { locationNotFoundController } diff --git a/src/server/location-not-found/cy/controller.js b/src/server/location-not-found/cy/controller.js index 6cfb9226..63c46267 100644 --- a/src/server/location-not-found/cy/controller.js +++ b/src/server/location-not-found/cy/controller.js @@ -1,25 +1,30 @@ -const searchLocationController = { +import { LOCATION_NOT_FOUND } from '~/src/server/data/constants' +import { english } from '~/src/server/data/en/en.js' + +const locationNotFoundController = { handler: (request, h) => { - return h.view('location-not-found/index', { - pageTitle: 'Check air quality - GOV.UK', - heading: 'Check air quality', - page: 'location', - serviceName: 'Check air quality', - searchParams: { - label: { - text: 'Where do you want to check?', - classes: 'govuk-label--l govuk-!-margin-bottom-6', - isPageHeading: true - }, - hint: { - text: 'Enter a location or postcode' - }, - id: 'location', - name: 'location' - }, - lang: request.query.lang + const locationData = request.yar.get('locationDataNotFound') || [] + const { locationNameOrPostcode, lang } = locationData + const { + notFoundLocation, + home, + footerTxt, + phaseBanner, + backlink, + cookieBanner + } = english + return h.view(LOCATION_NOT_FOUND, { + userLocation: locationNameOrPostcode, + serviceName: notFoundLocation.heading, + paragraph: notFoundLocation.paragraphs, + pageTitle: `${notFoundLocation.paragraphs.a} ${locationNameOrPostcode} - ${home.pageTitle}`, + footerTxt, + phaseBanner, + backlink, + cookieBanner, + lang }) } } -export { searchLocationController } +export { locationNotFoundController } diff --git a/src/server/location-not-found/cy/index.js b/src/server/location-not-found/cy/index.js index 54316e4d..7c61bf14 100644 --- a/src/server/location-not-found/cy/index.js +++ b/src/server/location-not-found/cy/index.js @@ -1,18 +1,18 @@ -import { searchLocationController } from '~/src/server/search-location/controller' +import { locationNotFoundController } from '~/src/server/location-not-found/cy/controller' -const searchLocationCy = { +const locationNotFoundCy = { plugin: { - name: 'lleoliad', + name: 'lleoliad-heb-ei-ganfod', register: async (server) => { server.route([ { - method: 'POST', - path: '/lleoliad{id}', - ...searchLocationController + method: 'GET', + path: '/lleoliad-heb-ei-ganfod/cy', + ...locationNotFoundController } ]) } } } -export { searchLocationCy } +export { locationNotFoundCy } diff --git a/src/server/location-not-found/index.js b/src/server/location-not-found/index.js index 5b766c41..5f372cdd 100644 --- a/src/server/location-not-found/index.js +++ b/src/server/location-not-found/index.js @@ -1,18 +1,18 @@ -import { searchLocationController } from '~/src/server/search-location/controller' +import { locationNotFoundController } from '~/src/server/location-not-found/controller' -const searchLocation = { +const locationNotFound = { plugin: { - name: 'location', + name: 'location-not-found', register: async (server) => { server.route([ { - method: 'POST', - path: '/location{id}', - ...searchLocationController + method: 'GET', + path: '/location-not-found', + ...locationNotFoundController } ]) } } } -export { searchLocation } +export { locationNotFound } diff --git a/src/server/locations/helpers/fetch-data.js b/src/server/locations/helpers/fetch-data.js index 7f042bd3..0de2c76c 100644 --- a/src/server/locations/helpers/fetch-data.js +++ b/src/server/locations/helpers/fetch-data.js @@ -82,7 +82,7 @@ async function fetchData(locationType, userLocation, request, h) { () => { // Assuming you have access to the request object here if (locationType === 'ni-location') { - refreshOAuthToken(request) + refreshOAuthToken() } else { clearRefreshInterval() } diff --git a/src/server/locations/middleware.js b/src/server/locations/middleware.js index fb0b7400..9bdcc52f 100644 --- a/src/server/locations/middleware.js +++ b/src/server/locations/middleware.js @@ -75,16 +75,8 @@ const searchMiddleware = async (request, h) => { let { results } = getOSPlaces if (!results || results.length === 0 || getOSPlaces === 'wrong postcode') { - return handleLocationNotFound(h, { - locationNameOrPostcode, - notFoundLocation, - home, - footerTxt, - phaseBanner, - backlink, - cookieBanner, - lang - }) + request.yar.set('locationDataNotFound', { locationNameOrPostcode, lang }) + return h.redirect('/location-not-found').takeover() } // Remove duplicates from the results array results = Array.from( diff --git a/src/server/router.js b/src/server/router.js index 4d5cc055..af4fe1ca 100644 --- a/src/server/router.js +++ b/src/server/router.js @@ -29,6 +29,8 @@ import { health } from '~/src/server/health/index' import { config } from '~/src/config' import { multipleResults } from '~/src/server/multiple-results/index' import { multipleResultsCy } from '~/src/server/multiple-results/cy/index' +import { locationNotFound } from '~/src/server/location-not-found/index' +import { locationNotFoundCy } from '~/src/server/location-not-found/cy/index' const sessionCookiePassword = config.get('sessionCookiePassword') @@ -78,6 +80,8 @@ const router = { accessibilityCy, multipleResults, multipleResultsCy, + locationNotFound, + locationNotFoundCy, health ]) await server.register({