generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* create view application route * handle errors gracefully
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Request, Response, Router } from 'express' | ||
import { APPLICATION_TYPES } from '../../constants/applicationTypes' | ||
import asyncMiddleware from '../../middleware/asyncMiddleware' | ||
import AuditService, { Page } from '../../services/auditService' | ||
|
||
export default function viewApplicationRoutes({ auditService }: { auditService: AuditService }): Router { | ||
const router = Router() | ||
|
||
router.get( | ||
'/view/:applicationId', | ||
asyncMiddleware(async (req: Request, res: Response) => { | ||
const { applicationId } = req.params | ||
|
||
const application = { | ||
id: applicationId, | ||
type: 'swap-visiting-orders-for-pin-credit', | ||
dept: 'Business Hub', | ||
} | ||
|
||
if (!application) { | ||
res.redirect('/applications') | ||
return | ||
} | ||
|
||
await auditService.logPageView(Page.VIEW_APPLICATION_PAGE, { | ||
who: res.locals.user.username, | ||
correlationId: req.id, | ||
}) | ||
|
||
const applicationType = APPLICATION_TYPES.find(type => type.value === application.type) | ||
|
||
if (!applicationType) { | ||
res.redirect('/applications?error=unknown-type') | ||
return | ||
} | ||
|
||
res.render(`pages/view-application/${application.type}`, { | ||
title: applicationType.name, | ||
application, | ||
}) | ||
}), | ||
) | ||
|
||
return router | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
server/views/pages/view-application/swap-visiting-orders-for-pin-credit.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% from "govuk/components/back-link/macro.njk" import govukBackLink %} | ||
{% from "govuk/components/button/macro.njk" import govukButton %} | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
|
||
{% extends "../../partials/layout.njk" %} | ||
|
||
{% set pageTitle = applicationName + " - " + title %} | ||
{% set mainClasses = "app-container govuk-body applications-landing-page" %} | ||
|
||
{% block content %} | ||
<div class="govuk-body govuk-width-container"> | ||
{{ govukBackLink({ | ||
text: "Back", | ||
href: "/" | ||
}) }} | ||
|
||
<span class="govuk-caption-xl">{{ application.dept }}</span> | ||
<h1 class="govuk-heading-xl govuk-!-margin-top-0">{{ title }}</h1> | ||
</div> | ||
{% endblock %} |