Skip to content

Commit

Permalink
activated page not found route, ni poscode entry in uk location.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses-cognizant committed Jan 10, 2025
1 parent d661459 commit ee27692
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 66 deletions.
46 changes: 25 additions & 21 deletions src/server/location-not-found/controller.js
Original file line number Diff line number Diff line change
@@ -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 }
45 changes: 25 additions & 20 deletions src/server/location-not-found/cy/controller.js
Original file line number Diff line number Diff line change
@@ -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 }
14 changes: 7 additions & 7 deletions src/server/location-not-found/cy/index.js
Original file line number Diff line number Diff line change
@@ -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 }
14 changes: 7 additions & 7 deletions src/server/location-not-found/index.js
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 1 addition & 1 deletion src/server/locations/helpers/fetch-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
12 changes: 2 additions & 10 deletions src/server/locations/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/server/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -78,6 +80,8 @@ const router = {
accessibilityCy,
multipleResults,
multipleResultsCy,
locationNotFound,
locationNotFoundCy,
health
])
await server.register({
Expand Down

0 comments on commit ee27692

Please sign in to comment.