Skip to content

Commit

Permalink
Move controllers in routes to singleton (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielburnley authored Nov 3, 2023
1 parent 107c41e commit 5eac5dc
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ export default function routes(services: Services): Router {

commonRoutes()

const overviewController = new OverviewController(
services.prisonerSearchService,
services.overviewPageService,
services.dataAccess.pathfinderApiClientBuilder,
services.dataAccess.manageSocCasesApiClientBuilder,
)

const prisonerScheduleController = new PrisonerScheduleController(services.dataAccess.prisonApiClientBuilder)
const prisonerCellHistoryController = new PrisonerCellHistoryController(services.dataAccess.prisonApiClientBuilder)

get('/prisoner/*', getFrontendComponents(services, config.apis.frontendComponents.latest))

get('/prisoner/:prisonerNumber', getPrisonerData(services), checkPrisonerInCaseload(), async (req, res, next) => {
const prisonerData = req.middleware?.prisonerData
const inmateDetail = req.middleware?.inmateDetail

const overviewController = new OverviewController(
services.prisonerSearchService,
services.overviewPageService,
services.dataAccess.pathfinderApiClientBuilder,
services.dataAccess.manageSocCasesApiClientBuilder,
)
return overviewController.displayOverview(req, res, prisonerData, inmateDetail)
})

Expand Down Expand Up @@ -173,7 +176,6 @@ export default function routes(services: Services): Router {
checkPrisonerInCaseload(),
async (req, res, next) => {
const prisonerData = req.middleware?.prisonerData
const prisonerScheduleController = new PrisonerScheduleController(services.dataAccess.prisonApiClientBuilder)
return prisonerScheduleController.displayPrisonerSchedule(req, res, prisonerData)
},
)
Expand Down Expand Up @@ -209,9 +211,6 @@ export default function routes(services: Services): Router {
checkPrisonerInCaseload(),
async (req, res, next) => {
const prisonerData = req.middleware?.prisonerData
const prisonerCellHistoryController = new PrisonerCellHistoryController(
services.dataAccess.prisonApiClientBuilder,
)
return prisonerCellHistoryController.displayPrisonerCellHistory(req, res, prisonerData)
},
)
Expand Down

0 comments on commit 5eac5dc

Please sign in to comment.