Skip to content

Commit

Permalink
Rename routes
Browse files Browse the repository at this point in the history
This follows our convention (followed most of the time!) of starting with the resource name i.e. what we called the model!

Then, the main route (show all records) is `index.*.js`/`index.njk` and for an individual it is `view.*.js`/`view.njk`

Co-authored-by: Stuart Adair <[email protected]>
  • Loading branch information
Cruikshanks and StuAA78 committed Jan 13, 2025
1 parent 6f1ffca commit 30d3ba2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

/**
* Controller for /returns endpoints
* @module ReturnsController
* Controller for /return-logs endpoints
* @module ReturnLogsController
*/

const Boom = require('@hapi/boom')

const ReturnLogService = require('../services/returns/return-log.service.js')
const ReturnLogService = require('../services/return-logs/return-log.service.js')

async function returnLog(request, h) {
async function view(request, h) {
// TODO: Consider whether we want to read the id as a query param or if we want to pass it in the route itself. This
// would require URL-encoding and -decoding it since ids can contain slashes.
const { id } = request.query
Expand All @@ -20,9 +20,9 @@ async function returnLog(request, h) {

const pageData = await ReturnLogService.go(request, id)

return h.view('returns/return-log.njk', { ...pageData })
return h.view('return-logs/view.njk', { activeNavBar: 'search', ...pageData })
}

module.exports = {
returnLog
view
}
4 changes: 2 additions & 2 deletions app/plugins/router.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const LicenceRoutes = require('../routes/licence.routes.js')
const LicenceEndDatesRoutes = require('../routes/licences-end-dates.routes.js')
const MonitoringStationRoutes = require('../routes/monitoring-station.routes.js')
const ReturnLogSetupRoutes = require('../routes/return-logs-setup.routes.js')
const ReturnsRoutes = require('../routes/returns.routes.js')
const ReturnLogRoutes = require('../routes/return-logs.routes.js')
const ReturnVersionsSetupRoutes = require('../routes/return-versions-setup.routes.js')
const ReturnVersionsRoutes = require('../routes/return-versions.routes.js')
const RootRoutes = require('../routes/root.routes.js')
Expand All @@ -52,7 +52,7 @@ const routes = [
...JobRoutes,
...MonitoringStationRoutes,
...ReturnLogSetupRoutes,
...ReturnsRoutes,
...ReturnLogRoutes,
...ReturnVersionsRoutes,
...ReturnVersionsSetupRoutes,
...DataRoutes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

const ReturnsController = require('../controllers/returns.controller.js')
const ReturnLogsController = require('../controllers/return-logs.controller.js')

const routes = [
{
method: 'GET',
path: '/returns/return-log',
path: '/return-logs',
options: {
handler: ReturnsController.returnLog,
handler: ReturnLogsController.view,
app: {
plainOutput: true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @module ReturnLogService
*/

const FetchReturnLogService = require('./fetch-return-log.service.js')
const LegacyRequest = require('../../requests/legacy.request.js')
const ReturnLogPresenter = require('../../presenters/return-logs/view.presenter.js')

Expand All @@ -19,6 +20,9 @@ const ReturnLogPresenter = require('../../presenters/return-logs/view.presenter.
async function go(request, returnId) {
const { id: userId } = request.auth.credentials.user

const returnLog = await FetchReturnLogService.go(returnId)
console.log('🚀 ~ go ~ returnLog:', returnLog)

const result = await LegacyRequest.get('water', 'returns?returnId=' + returnId, userId)

const { body } = result.response
Expand All @@ -27,7 +31,10 @@ async function go(request, returnId) {

// TODO: Check licence in CRM to ensure user has access

return pageData
return {
pageTitle: 'Abstraction return',
...pageData
}
}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% block content %}
<div class="govuk-body">
<span class="govuk-caption-l">Licence {{ licenceNumber }}</span>
<h1 class="govuk-heading-l">Abstraction return</h1>
<h1 class="govuk-heading-l">{{ pageTitle }}</h1>
<p class="govuk-body">
{{ statusTag(status, true) }}
</p>
Expand Down

0 comments on commit 30d3ba2

Please sign in to comment.