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.
VB-5036 Refactor to split visit details page code (#928)
- Loading branch information
Showing
8 changed files
with
788 additions
and
612 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
import { RequestHandler, Router } from 'express' | ||
import { BadRequest } from 'http-errors' | ||
import { Services } from '../../services' | ||
import asyncMiddleware from '../../middleware/asyncMiddleware' | ||
import VisitDetailsController from './visitDetailsController' | ||
import { isValidVisitReference } from '../validationChecks' | ||
|
||
export default function routes(services: Services): Router { | ||
const router = Router() | ||
|
||
const get = (path: string | string[], handler: RequestHandler) => router.get(path, asyncMiddleware(handler)) | ||
|
||
// middleware to ensure valid visit reference | ||
router.use('/:reference', (req, res, next) => { | ||
const { reference } = req.params | ||
if (!isValidVisitReference(reference)) { | ||
throw new BadRequest() | ||
} | ||
next() | ||
}) | ||
|
||
const visitDetails = new VisitDetailsController( | ||
services.auditService, | ||
services.prisonerSearchService, | ||
services.supportedPrisonsService, | ||
services.visitService, | ||
) | ||
|
||
get('/:reference', visitDetails.view()) | ||
|
||
return router | ||
} |
Oops, something went wrong.