Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move controllers in routes to singleton #330

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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