diff --git a/server/@types/express/index.d.ts b/server/@types/express/index.d.ts index 1d64cd5e..e4e589fa 100644 --- a/server/@types/express/index.d.ts +++ b/server/@types/express/index.d.ts @@ -1,5 +1,6 @@ import SessionAdjustment from '../AdjustmentTypes' import type { UserDetails } from '../../services/userService' +import { PrisonApiPrisoner } from '../prisonApi/prisonClientTypes' export default {} @@ -29,6 +30,7 @@ export declare global { interface Locals { user: Express.User + prisoner: PrisonApiPrisoner } } } diff --git a/server/app.ts b/server/app.ts index bbf3cf45..54b78ba0 100755 --- a/server/app.ts +++ b/server/app.ts @@ -18,6 +18,7 @@ import setUpWebSession from './middleware/setUpWebSession' import routes from './routes' import type { Services } from './services' +import populateCurrentPrisoner from './middleware/populateCurrentPrisoner' export default function createApp(services: Services): express.Application { const app = express() @@ -37,6 +38,7 @@ export default function createApp(services: Services): express.Application { app.use(authorisationMiddleware()) app.use(setUpCsrf()) app.use(setUpCurrentUser(services)) + app.use('/:nomsId', populateCurrentPrisoner(services.prisonerService)) app.use(routes(services)) diff --git a/server/middleware/populateCurrentPrisoner.ts b/server/middleware/populateCurrentPrisoner.ts new file mode 100644 index 00000000..7055e216 --- /dev/null +++ b/server/middleware/populateCurrentPrisoner.ts @@ -0,0 +1,27 @@ +import { RequestHandler } from 'express' +import PrisonerService from '../services/prisonerService' +import FullPageError from '../model/FullPageError' +import logger from '../../logger' + +export default function populateCurrentPrisoner(prisonerService: PrisonerService): RequestHandler { + return async (req, res, next) => { + const { token, caseloads } = res.locals.user + const { nomsId } = req.params + + if (token && nomsId) { + try { + const prisoner = await prisonerService.getPrisonerDetail(nomsId, caseloads, token) + if (caseloads.includes(prisoner.agencyId)) { + res.locals.prisoner = prisoner + } else { + throw FullPageError.notInCaseLoadError() + } + } catch (error) { + logger.error(error, `Failed to get prisoner with prisoner number: ${nomsId}`) + return next(error) + } + } + + return next() + } +} diff --git a/server/model/adjustmentsHubViewModel.ts b/server/model/adjustmentsHubViewModel.ts index 043a453c..2da6c2db 100644 --- a/server/model/adjustmentsHubViewModel.ts +++ b/server/model/adjustmentsHubViewModel.ts @@ -1,6 +1,5 @@ import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import { IdentifyRemandDecision, RemandResult } from '../@types/identifyRemandPeriods/identifyRemandPeriodsTypes' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { calculateReleaseDatesCheckInformationUrl } from '../utils/utils' import adjustmentTypes, { AdjustmentType } from './adjustmentTypes' @@ -26,7 +25,7 @@ export default class AdjustmentsHubViewModel { public messageType: AdjustmentType constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, public adjustments: Adjustment[], public relevantRemand: RemandResult, public remandDecision: IdentifyRemandDecision, @@ -92,7 +91,7 @@ export default class AdjustmentsHubViewModel { } public calculateReleaseDatesUrl() { - return calculateReleaseDatesCheckInformationUrl(this.prisonerDetail) + return calculateReleaseDatesCheckInformationUrl(this.prisonerNumber) } private allDeductionsOnDps() { diff --git a/server/model/recallModel.ts b/server/model/recallModel.ts index b80c288e..230420dc 100644 --- a/server/model/recallModel.ts +++ b/server/model/recallModel.ts @@ -1,11 +1,9 @@ import dayjs from 'dayjs' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import RecallForm from './recallForm' export default class RecallModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustments: Adjustment[], public form: RecallForm, ) {} diff --git a/server/model/remandChangeModel.ts b/server/model/remandChangeModel.ts index 65dee002..b6a44d5f 100644 --- a/server/model/remandChangeModel.ts +++ b/server/model/remandChangeModel.ts @@ -1,11 +1,10 @@ import { Adjustment } from '../@types/adjustments/adjustmentsTypes' -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import { UnusedDeductionCalculationResponse } from '../@types/calculateReleaseDates/calculateReleaseDatesClientTypes' import { offencesForAdjustment, remandRelatedValidationSummary } from '../utils/utils' export default class RemandChangeModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustment: Adjustment, private sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], private calculatedUnusedDeductions: UnusedDeductionCalculationResponse, diff --git a/server/model/remandDatesModel.ts b/server/model/remandDatesModel.ts index 2c3ba4f8..e24bdbf7 100644 --- a/server/model/remandDatesModel.ts +++ b/server/model/remandDatesModel.ts @@ -1,21 +1,20 @@ import SessionAdjustment from '../@types/AdjustmentTypes' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import RemandDatesForm from './remandDatesForm' export default class RemandDatesModel { constructor( public id: string, - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, public adjustments: SessionAdjustment[], public form: RemandDatesForm, public addOrEdit: string = null, ) {} public backlink(): string { - if (this.addOrEdit === 'edit') return `/${this.prisonerDetail.offenderNo}/remand/edit/${this.id}` + if (this.addOrEdit === 'edit') return `/${this.prisonerNumber}/remand/edit/${this.id}` if (this.adjustments.length > 1 || this.adjustments[0].complete) { - return `/${this.prisonerDetail.offenderNo}/remand/review` + return `/${this.prisonerNumber}/remand/review` } - return `/${this.prisonerDetail.offenderNo}` + return `/${this.prisonerNumber}` } } diff --git a/server/model/remandReviewModel.ts b/server/model/remandReviewModel.ts index 06d8a737..e06a18ab 100644 --- a/server/model/remandReviewModel.ts +++ b/server/model/remandReviewModel.ts @@ -1,6 +1,6 @@ import dayjs from 'dayjs' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import { daysBetween, offencesForAdjustment, remandRelatedValidationSummary } from '../utils/utils' import ReviewRemandForm from './reviewRemandForm' import { CalculateReleaseDatesValidationMessage } from '../@types/calculateReleaseDates/calculateReleaseDatesClientTypes' @@ -9,7 +9,7 @@ export default class RemandReviewModel { adjustmentIds: string[] constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, public adjustments: Record, private sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], private calculateReleaseDatesValidationMessages: CalculateReleaseDatesValidationMessage[], @@ -29,7 +29,7 @@ export default class RemandReviewModel { } public backlink(): string { - return `/${this.prisonerDetail.offenderNo}/remand/offences/add/${this.adjustmentIds[0]}` + return `/${this.prisonerNumber}/remand/offences/add/${this.adjustmentIds[0]}` } public adjustmentSummary(id: string) { @@ -49,7 +49,7 @@ export default class RemandReviewModel { actions: { items: [ { - href: `/${this.prisonerDetail.offenderNo}/remand/dates/add/${id}`, + href: `/${this.prisonerNumber}/remand/dates/add/${id}`, text: 'Edit', visuallyHiddenText: 'remand', }, @@ -75,7 +75,7 @@ export default class RemandReviewModel { actions: { items: [ { - href: `/${this.prisonerDetail.offenderNo}/remand/offences/add/${id}`, + href: `/${this.prisonerNumber}/remand/offences/add/${id}`, text: 'Edit', visuallyHiddenText: 'remand', }, diff --git a/server/model/remandSaveModel.ts b/server/model/remandSaveModel.ts index 8f4d7310..0dace3f8 100644 --- a/server/model/remandSaveModel.ts +++ b/server/model/remandSaveModel.ts @@ -1,11 +1,9 @@ import dayjs from 'dayjs' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { daysBetween } from '../utils/utils' export default class RemandSaveModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustments: Adjustment[], public unusedDeductions: number, ) {} diff --git a/server/model/remandSelectOffencesModel.ts b/server/model/remandSelectOffencesModel.ts index 11b6b478..a450ad54 100644 --- a/server/model/remandSelectOffencesModel.ts +++ b/server/model/remandSelectOffencesModel.ts @@ -1,9 +1,5 @@ import SessionAdjustment from '../@types/AdjustmentTypes' -import { - PrisonApiOffence, - PrisonApiOffenderSentenceAndOffences, - PrisonApiPrisoner, -} from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffence, PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import PrisonerService from '../services/prisonerService' import { daysBetween, groupBy } from '../utils/utils' import RemandOffencesForm from './remandOffencesForm' @@ -13,7 +9,7 @@ export default class RemandSelectOffencesModel { constructor( public id: string, - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, public adjustment: SessionAdjustment, public form: RemandOffencesForm, sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], @@ -23,11 +19,11 @@ export default class RemandSelectOffencesModel { } public backlink(): string { - if (this.addOrEdit === 'edit') return `/${this.prisonerDetail.offenderNo}/remand/edit/${this.id}` + if (this.addOrEdit === 'edit') return `/${this.prisonerNumber}/remand/edit/${this.id}` if (this.adjustment.complete) { - return `/${this.prisonerDetail.offenderNo}/remand/review` + return `/${this.prisonerNumber}/remand/review` } - return `/${this.prisonerDetail.offenderNo}/remand/dates/add/${this.id}` + return `/${this.prisonerNumber}/remand/dates/add/${this.id}` } public days(): number { diff --git a/server/model/remandViewModel.ts b/server/model/remandViewModel.ts index 05b7e29f..13270cc1 100644 --- a/server/model/remandViewModel.ts +++ b/server/model/remandViewModel.ts @@ -1,11 +1,10 @@ import dayjs from 'dayjs' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import { offencesForAdjustment } from '../utils/utils' export default class RemandViewModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustments: Adjustment[], private sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], ) {} diff --git a/server/model/removeModel.ts b/server/model/removeModel.ts index e360eb40..142de25c 100644 --- a/server/model/removeModel.ts +++ b/server/model/removeModel.ts @@ -1,11 +1,9 @@ -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import { AdjustmentType } from './adjustmentTypes' import ReviewModel from './reviewModel' export default class RemoveModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustment: Adjustment, public adjustmentType: AdjustmentType, ) {} diff --git a/server/model/reviewAndSubmitAdaViewModel.ts b/server/model/reviewAndSubmitAdaViewModel.ts index fde76b2c..f69f8dc6 100644 --- a/server/model/reviewAndSubmitAdaViewModel.ts +++ b/server/model/reviewAndSubmitAdaViewModel.ts @@ -1,10 +1,8 @@ import dayjs from 'dayjs' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment, EditableAdjustment } from '../@types/adjustments/adjustmentsTypes' export default class ReviewAndSubmitAdaViewModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustments: EditableAdjustment[], public existingAdjustments: Adjustment[], public quashedAdjustments: Adjustment[], diff --git a/server/model/reviewModel.ts b/server/model/reviewModel.ts index 079327e6..46638569 100644 --- a/server/model/reviewModel.ts +++ b/server/model/reviewModel.ts @@ -1,15 +1,11 @@ import dayjs from 'dayjs' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment, EditableAdjustment } from '../@types/adjustments/adjustmentsTypes' import adjustmentTypes, { AdjustmentType } from './adjustmentTypes' import ualType from './ualType' import { daysBetween } from '../utils/utils' export default class ReviewModel { - constructor( - public prisonerDetail: PrisonApiPrisoner, - public adjustment: EditableAdjustment, - ) {} + constructor(public adjustment: EditableAdjustment) {} public adjustmentType(): AdjustmentType { return adjustmentTypes.find(it => it.value === this.adjustment.adjustmentType) diff --git a/server/model/taggedBailDaysModel.ts b/server/model/taggedBailDaysModel.ts index 5ea0353a..f9a019ea 100644 --- a/server/model/taggedBailDaysModel.ts +++ b/server/model/taggedBailDaysModel.ts @@ -1,10 +1,9 @@ -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import TaggedBailDaysForm from './taggedBailDaysForm' import SessionAdjustment from '../@types/AdjustmentTypes' export default class TaggedBailDaysModel { constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, private addOrEdit: string, private id: string, public form: TaggedBailDaysForm, @@ -13,8 +12,8 @@ export default class TaggedBailDaysModel { public backlink(): string { if (this.adjustment.complete) { - return `/${this.prisonerDetail.offenderNo}/tagged-bail/review/${this.addOrEdit}/${this.id}` + return `/${this.prisonerNumber}/tagged-bail/review/${this.addOrEdit}/${this.id}` } - return `/${this.prisonerDetail.offenderNo}/tagged-bail/select-case/${this.addOrEdit}/${this.id}` + return `/${this.prisonerNumber}/tagged-bail/select-case/${this.addOrEdit}/${this.id}` } } diff --git a/server/model/taggedBailRemoveModel.ts b/server/model/taggedBailRemoveModel.ts index 52aa9e59..b92b4a60 100644 --- a/server/model/taggedBailRemoveModel.ts +++ b/server/model/taggedBailRemoveModel.ts @@ -1,11 +1,11 @@ -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import { AdjustmentType } from './adjustmentTypes' import { dateToString } from '../utils/utils' export default class TaggedBailRemoveModel { constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, public adjustment: Adjustment, public adjustmentType: AdjustmentType, public sentenceAndOffence: PrisonApiOffenderSentenceAndOffences, @@ -13,7 +13,7 @@ export default class TaggedBailRemoveModel { ) {} public backlink(): string { - return `/${this.prisonerDetail.offenderNo}` + return `/${this.prisonerNumber}` } public rows() { diff --git a/server/model/taggedBailReviewModel.ts b/server/model/taggedBailReviewModel.ts index ef572907..7d2ad033 100644 --- a/server/model/taggedBailReviewModel.ts +++ b/server/model/taggedBailReviewModel.ts @@ -1,10 +1,10 @@ -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import SessionAdjustment from '../@types/AdjustmentTypes' import { dateToString, getMostRecentSentenceAndOffence } from '../utils/utils' export default class TaggedBailReviewModel { constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, private addOrEdit: string, public id: string, private sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], @@ -12,7 +12,7 @@ export default class TaggedBailReviewModel { ) {} public backlink(): string { - return `/${this.prisonerDetail.offenderNo}/tagged-bail/days/${this.addOrEdit}/${this.id}` + return `/${this.prisonerNumber}/tagged-bail/days/${this.addOrEdit}/${this.id}` } public getCaseDetails() { diff --git a/server/model/taggedBailSelectCaseModel.ts b/server/model/taggedBailSelectCaseModel.ts index 8057b8e4..82bc92b1 100644 --- a/server/model/taggedBailSelectCaseModel.ts +++ b/server/model/taggedBailSelectCaseModel.ts @@ -1,4 +1,4 @@ -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import SessionAdjustment from '../@types/AdjustmentTypes' import { getActiveSentencesByCaseSequence, SentencesByCaseSequence } from '../utils/utils' @@ -8,7 +8,7 @@ export default class TaggedBailSelectCaseModel { private sentencesByCaseSequence: SentencesByCaseSequence[] constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, private sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], private addOrEdit: string, private id: string, @@ -19,9 +19,9 @@ export default class TaggedBailSelectCaseModel { public backlink(): string { if (this.adjustment.complete) { - return `/${this.prisonerDetail.offenderNo}/tagged-bail/review/${this.addOrEdit}/${this.id}` + return `/${this.prisonerNumber}/tagged-bail/review/${this.addOrEdit}/${this.id}` } - return `/${this.prisonerDetail.offenderNo}` + return `/${this.prisonerNumber}` } // returns the sentence data for each unique case sequence; i.e. the record that has the earliest sentence date when multiple ones exist @@ -31,8 +31,8 @@ export default class TaggedBailSelectCaseModel { ...it.sentences.sort((a, b) => new Date(a.sentenceDate).getTime() - new Date(b.sentenceDate).getTime())[0], selected: this.adjustment.taggedBail?.caseSequence === it.caseSequence, selectCaseHref: this.adjustment.complete - ? `/${this.prisonerDetail.offenderNo}/tagged-bail/review/${this.addOrEdit}/${this.id}?caseSequence=${it.caseSequence}` - : `/${this.prisonerDetail.offenderNo}/tagged-bail/days/${this.addOrEdit}/${this.id}?caseSequence=${it.caseSequence}`, + ? `/${this.prisonerNumber}/tagged-bail/review/${this.addOrEdit}/${this.id}?caseSequence=${it.caseSequence}` + : `/${this.prisonerNumber}/tagged-bail/days/${this.addOrEdit}/${this.id}?caseSequence=${it.caseSequence}`, } }) } diff --git a/server/model/taggedBailViewModel.ts b/server/model/taggedBailViewModel.ts index 3e94cfde..f99ae890 100644 --- a/server/model/taggedBailViewModel.ts +++ b/server/model/taggedBailViewModel.ts @@ -1,4 +1,4 @@ -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import { AdjustmentType } from './adjustmentTypes' import { @@ -12,7 +12,7 @@ export default class TaggedBailViewModel { private sentencesByCaseSequence: SentencesByCaseSequence[] constructor( - public prisonerDetail: PrisonApiPrisoner, + public prisonerNumber: string, public adjustments: Adjustment[], public adjustmentType: AdjustmentType, public sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[], @@ -21,7 +21,7 @@ export default class TaggedBailViewModel { } public backlink(): string { - return `/${this.prisonerDetail.offenderNo}` + return `/${this.prisonerNumber}` } public columnHeadings() { diff --git a/server/model/viewModel.ts b/server/model/viewModel.ts index c89db5e3..4e53a320 100644 --- a/server/model/viewModel.ts +++ b/server/model/viewModel.ts @@ -1,5 +1,4 @@ import dayjs from 'dayjs' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import { AdjustmentType } from './adjustmentTypes' import ualType from './ualType' @@ -9,7 +8,6 @@ export default class ViewModel { public adjustments: Adjustment[] constructor( - public prisonerDetail: PrisonApiPrisoner, allAdjustments: Adjustment[], public adjustmentType: AdjustmentType, public remandDecision: IdentifyRemandDecision, diff --git a/server/model/warningModel.ts b/server/model/warningModel.ts index 27576b82..73199785 100644 --- a/server/model/warningModel.ts +++ b/server/model/warningModel.ts @@ -1,11 +1,9 @@ -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment, ValidationMessage } from '../@types/adjustments/adjustmentsTypes' import WarningForm from './warningForm' import adjustmentTypes from './adjustmentTypes' export default class WarningModel { constructor( - public prisonerDetail: PrisonApiPrisoner, public adjustment: Adjustment, public validationMessage: ValidationMessage, public form: WarningForm, diff --git a/server/routes/additionalDaysAwardedRoutes.test.ts b/server/routes/additionalDaysAwardedRoutes.test.ts index 45c2c203..5e3ba4b0 100644 --- a/server/routes/additionalDaysAwardedRoutes.test.ts +++ b/server/routes/additionalDaysAwardedRoutes.test.ts @@ -3,7 +3,6 @@ import request from 'supertest' import { appWithAllRoutes, user } from './testutils/appSetup' import PrisonerService from '../services/prisonerService' import AdjustmentsService from '../services/adjustmentsService' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import IdentifyRemandPeriodsService from '../services/identifyRemandPeriodsService' import AdjustmentsStoreService from '../services/adjustmentsStoreService' import AdditionalDaysAwardedService from '../services/additionalDaysAwardedService' @@ -26,15 +25,6 @@ const additionalDaysAwardedService = new AdditionalDaysAwardedService( const NOMS_ID = 'ABC123' -const stubbedPrisonerData = { - offenderNo: NOMS_ID, - firstName: 'Anon', - lastName: 'Nobody', - dateOfBirth: '24/06/2000', - bookingId: 12345, - agencyId: 'LDS', -} as PrisonApiPrisoner - const allPadas = { awaitingApproval: [ { @@ -221,7 +211,6 @@ afterEach(() => { describe('Additional Days Awarded routes tests', () => { describe('Review and approve tests', () => { it('GET /{nomsId}/additional-days/review-and-approve when only PADAs exist redirects to review and submit', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestSentence: new Date(), earliestExcludingRecalls: new Date(), @@ -235,7 +224,6 @@ describe('Additional Days Awarded routes tests', () => { }) it('GET /{nomsId}/additional-days/review-and-approve when no awaiting approval records exist does not redirect', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestSentence: new Date(), earliestExcludingRecalls: new Date(), @@ -246,7 +234,6 @@ describe('Additional Days Awarded routes tests', () => { }) it('GET /{nomsId}/additional-days/review-and-approve when quashed records exist does not redirect', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestSentence: new Date(), earliestExcludingRecalls: new Date(), @@ -257,7 +244,6 @@ describe('Additional Days Awarded routes tests', () => { }) it('GET /{nomsId}/additional-days/review-and-approve when mix of PADAs and others exist does not redirect', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestSentence: new Date(), earliestExcludingRecalls: new Date(), diff --git a/server/routes/additionalDaysAwardedRoutes.ts b/server/routes/additionalDaysAwardedRoutes.ts index 1c12b256..b40744f8 100644 --- a/server/routes/additionalDaysAwardedRoutes.ts +++ b/server/routes/additionalDaysAwardedRoutes.ts @@ -13,19 +13,16 @@ export default class AdditionalDaysAwardedRoutes { ) {} public intercept: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId, offenderNo } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) - const adjustments = await new AdjustmentsClient(token).findByPerson(prisonerDetail.offenderNo) + const adjustments = await new AdjustmentsClient(token).findByPerson(offenderNo) const intercept: AdaIntercept = await this.additionalDaysAwardedService.shouldIntercept( req, - prisonerDetail, + offenderNo, adjustments, startOfSentenceEnvelope.earliestExcludingRecalls, token, @@ -37,20 +34,16 @@ export default class AdditionalDaysAwardedRoutes { return res.render('pages/adjustments/additional-days/intercept', { model: { - prisonerDetail, intercept, }, }) } public reviewAndApprove: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { prisoner } = res.locals + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(prisoner.bookingId, token) const adasToReview: AdasToReview = await this.additionalDaysAwardedService.getAdasToApprove( req, @@ -63,7 +56,7 @@ export default class AdditionalDaysAwardedRoutes { // Intercepted for PADAs, none have been selected. await this.additionalDaysAwardedService.submitAdjustments( req, - prisonerDetail, + prisoner, startOfSentenceEnvelope.earliestExcludingRecalls, token, ) @@ -76,9 +69,6 @@ export default class AdditionalDaysAwardedRoutes { } return res.render('pages/adjustments/additional-days/review-and-approve', { - model: { - prisonerDetail, - }, adasToReview, }) } @@ -94,13 +84,10 @@ export default class AdditionalDaysAwardedRoutes { } public reviewPadas: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) const padasToReview = await this.additionalDaysAwardedService.getPadasToApprove( nomsId, @@ -109,15 +96,12 @@ export default class AdditionalDaysAwardedRoutes { ) return res.render('pages/adjustments/additional-days/review-prospective', { - model: { - prisonerDetail, - }, padasToReview, }) } public submitPadas: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params const padaForm = new PadaForm(req.body) @@ -125,11 +109,8 @@ export default class AdditionalDaysAwardedRoutes { await padaForm.validate() if (padaForm.errors.length) { - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) const padasToReview = await this.additionalDaysAwardedService.getPadasToApprove( nomsId, @@ -137,9 +118,6 @@ export default class AdditionalDaysAwardedRoutes { token, ) return res.render('pages/adjustments/additional-days/review-prospective', { - model: { - prisonerDetail, - }, padasToReview, padaForm, }) @@ -157,19 +135,15 @@ export default class AdditionalDaysAwardedRoutes { } public reviewAndSubmit: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user - const { nomsId } = req.params + const { token } = res.locals.user const { referrer } = req.query as Record - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) return res.render('pages/adjustments/additional-days/review-and-submit', { model: await this.additionalDaysAwardedService.getReviewAndSubmitModel( req, - prisonerDetail, + res.locals.prisoner, startOfSentenceEnvelope.earliestExcludingRecalls, token, ), @@ -178,17 +152,14 @@ export default class AdditionalDaysAwardedRoutes { } public submit: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) await this.additionalDaysAwardedService.submitAdjustments( req, - prisonerDetail, + res.locals.prisoner, startOfSentenceEnvelope.earliestExcludingRecalls, token, ) @@ -200,30 +171,22 @@ export default class AdditionalDaysAwardedRoutes { } public addWarning: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user - const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { token } = res.locals.user + const { bookingId } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) return res.render('pages/adjustments/additional-days/add-warning', { model: { - prisonerDetail, startOfSentenceEnvelope, }, }) } public view: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) const adas = await this.additionalDaysAwardedService.viewAdjustments( nomsId, @@ -233,7 +196,6 @@ export default class AdditionalDaysAwardedRoutes { return res.render('pages/adjustments/additional-days/view', { model: { - prisonerDetail, adas, }, }) diff --git a/server/routes/adjustmentRoutes.test.ts b/server/routes/adjustmentRoutes.test.ts index d7e849fd..2afe6f27 100644 --- a/server/routes/adjustmentRoutes.test.ts +++ b/server/routes/adjustmentRoutes.test.ts @@ -3,7 +3,6 @@ import request from 'supertest' import { appWithAllRoutes, user } from './testutils/appSetup' import PrisonerService from '../services/prisonerService' import AdjustmentsService from '../services/adjustmentsService' -import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import IdentifyRemandPeriodsService from '../services/identifyRemandPeriodsService' import { Remand, RemandResult } from '../@types/identifyRemandPeriods/identifyRemandPeriodsTypes' @@ -31,15 +30,6 @@ const additionalDaysAwardedService = new AdditionalDaysAwardedService( const NOMS_ID = 'ABC123' -const stubbedPrisonerData = { - offenderNo: NOMS_ID, - firstName: 'Anon', - lastName: 'Nobody', - dateOfBirth: '24/06/2000', - bookingId: 12345, - agencyId: 'LDS', -} as PrisonApiPrisoner - const remandResult = { chargeRemand: [], sentenceRemand: [ @@ -133,7 +123,6 @@ afterEach(() => { describe('Adjustment routes tests', () => { it('GET /{nomsId} hub with unused deductions', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestExcludingRecalls: new Date(), earliestSentence: new Date(), @@ -163,7 +152,6 @@ describe('Adjustment routes tests', () => { }) }) it('GET /{nomsId} hub unused deductions cannot be calculated', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestExcludingRecalls: new Date(), earliestSentence: new Date(), @@ -185,7 +173,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId} with remand role', () => { userInTest = userWithRemandRole - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([ { ...radaAdjustment, prisonName: 'Leeds', lastUpdatedDate: '2023-04-05' }, ]) @@ -204,7 +191,6 @@ describe('Adjustment routes tests', () => { }) }) it('GET /{nomsId} is intercepted if there is adas to review', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestExcludingRecalls: new Date(), earliestSentence: new Date(), @@ -221,7 +207,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId} relevant remand throws error', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([radaAdjustment]) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestExcludingRecalls: new Date(), @@ -237,7 +222,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/restored-additional-days/add', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([adaAdjustment]) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestExcludingRecalls: new Date(), @@ -255,13 +239,11 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/restored-additional-days/add with validation error redirect', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([]) return request(app).get(`/${NOMS_ID}/restored-additional-days/add`).redirects(1) }) it('POST /{nomsId}/restored-additional-days/add valid', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([]) const expectedStore = { ...radaAdjustment } delete expectedStore.daysTotal @@ -277,7 +259,6 @@ describe('Adjustment routes tests', () => { }) }) it('POST /{nomsId}/restored-additional-days/add empty form validation', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) .expect('Content-Type', /html/) @@ -288,7 +269,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add missing day and month validation and not number days', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) .send({ 'from-year': '2023', days: 'xyz' }) @@ -301,7 +281,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add invalid date and negative days', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) .send({ 'from-day': '36', 'from-month': '13', 'from-year': '2023', days: -1 }) @@ -314,7 +293,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add 2 digit year', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) .send({ 'from-day': '6', 'from-month': '3', 'from-year': '23', days: -1 }) @@ -326,7 +304,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add invalid date 29 Feb', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) .send({ 'from-day': '29', 'from-month': '02', 'from-year': '2023', days: 1 }) @@ -338,7 +315,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add zero days', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([]) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) @@ -351,7 +327,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add fraction days', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([]) return request(app) .post(`/${NOMS_ID}/restored-additional-days/add`) @@ -364,7 +339,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/add server side validation mesage', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([ { code: 'MORE_RADAS_THAN_ADAS', @@ -383,7 +357,6 @@ describe('Adjustment routes tests', () => { }) }) it('POST /{nomsId}/restored-additional-days/add server side warning mesage', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([ { code: 'RADA_REDUCES_BY_MORE_THAN_HALF', @@ -407,7 +380,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/restored-additional-days/edit should load adjustment from session', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([adaAdjustment]) adjustmentsStoreService.getOnly.mockReturnValue(radaAdjustment) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ @@ -428,7 +400,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/restored-additional-days/edit should load adjustment from server', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([adaAdjustment]) prisonerService.getStartOfSentenceEnvelope.mockResolvedValue({ earliestExcludingRecalls: new Date(), @@ -449,7 +420,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/restored-additional-days/edit valid', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([]) const expectedStore = { ...radaAdjustment, @@ -470,7 +440,6 @@ describe('Adjustment routes tests', () => { }) }) it('POST /{nomsId}/restored-additional-days/edit/{id} valid', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.validate.mockResolvedValue([]) const expectedStore = { ...radaAdjustment, id: 'this-is-an-id' } delete expectedStore.daysTotal @@ -486,7 +455,6 @@ describe('Adjustment routes tests', () => { }) }) it('GET /{nomsId}/warning display server side warning', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getOnly.mockReturnValue(radaAdjustment) adjustmentsService.validate.mockResolvedValue([ { @@ -527,7 +495,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/warning submit warning without an answer', () => { adjustmentsStoreService.getOnly.mockReturnValue({ ...radaAdjustment, id: undefined }) - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getOnly.mockReturnValue(radaAdjustment) adjustmentsService.validate.mockResolvedValue([ { @@ -548,7 +515,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/review', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getOnly.mockReturnValue(radaAdjustment) return request(app) @@ -566,7 +532,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/review', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getOnly.mockReturnValue({ ...radaAdjustment, id: undefined }) adjustmentsService.create.mockResolvedValue({ adjustmentIds: ['this-is-an-id'] }) adjustmentsService.get.mockResolvedValue({ ...radaAdjustment, id: 'this-is-an-id' }) @@ -585,7 +550,6 @@ describe('Adjustment routes tests', () => { }) }) it('POST /{nomsId}/review with a adjustment with an id', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getOnly.mockReturnValue({ ...radaAdjustment, id: 'this-is-an-id' }) adjustmentsService.get.mockResolvedValue({ ...radaAdjustment, id: 'this-is-an-id' }) return request(app) @@ -605,7 +569,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/{adjustmentType}/view', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.findByPerson.mockResolvedValue([ { ...radaAdjustment, id: 'this-is-an-id', lastUpdatedBy: 'Doris McNealy', status: 'ACTIVE', prisonName: 'Leeds' }, ]) @@ -626,7 +589,6 @@ describe('Adjustment routes tests', () => { }) it('GET /{nomsId}/{adjustmentType}/remove/{id}', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.get.mockResolvedValue(radaAdjustment) return request(app) @@ -640,7 +602,6 @@ describe('Adjustment routes tests', () => { }) it('POST /{nomsId}/{adjustmentType}/remove/{id}', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsService.get.mockResolvedValue(radaAdjustment) return request(app) diff --git a/server/routes/adjustmentRoutes.ts b/server/routes/adjustmentRoutes.ts index 0b021626..a0757c21 100644 --- a/server/routes/adjustmentRoutes.ts +++ b/server/routes/adjustmentRoutes.ts @@ -37,15 +37,7 @@ export default class AdjustmentRoutes { } public start: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user - const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - - return res.render('pages/adjustments/start', { - model: { - prisonerDetail, - }, - }) + return res.render('pages/adjustments/start') } public success: RequestHandler = async (req, res): Promise => { @@ -55,13 +47,10 @@ export default class AdjustmentRoutes { } public hub: RequestHandler = async (req, res): Promise => { - const { caseloads, token, roles } = res.locals.user + const { token, roles } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const { bookingId, offenderNo } = res.locals.prisoner + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) const message = req.flash('message') const messageExists = message && message[0] @@ -91,7 +80,7 @@ export default class AdjustmentRoutes { if (!messageExists) { const intercept = await this.additionalDaysAwardedService.shouldIntercept( req, - prisonerDetail, + offenderNo, adjustments, startOfSentenceEnvelope.earliestExcludingRecalls, token, @@ -112,7 +101,7 @@ export default class AdjustmentRoutes { } return res.render('pages/adjustments/hub', { model: new AdjustmentsHubViewModel( - prisonerDetail, + offenderNo, adjustments, relevantRemand, remandDecision, @@ -129,8 +118,9 @@ export default class AdjustmentRoutes { } public form: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, adjustmentTypeUrl, addOrEdit, id } = req.params + const { bookingId } = res.locals.prisoner if (!['edit', 'add'].includes(addOrEdit)) { throw FullPageError.notFoundError() @@ -140,12 +130,9 @@ export default class AdjustmentRoutes { if (!adjustmentType) { return res.redirect(`/${nomsId}`) } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + if (adjustmentType.value === 'RESTORATION_OF_ADDITIONAL_DAYS_AWARDED') { - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) const adjustments = await this.adjustmentsService.findByPerson( nomsId, startOfSentenceEnvelope.earliestSentence, @@ -171,31 +158,31 @@ export default class AdjustmentRoutes { : AdjustmentsFormFactory.fromType(adjustmentType) return res.render('pages/adjustments/form', { - model: { prisonerDetail, form, addOrEdit, id }, + model: { form, addOrEdit, id }, }) } public submitForm: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, adjustmentTypeUrl, addOrEdit, id } = req.params + const { bookingId } = res.locals.prisoner const adjustmentType = adjustmentTypes.find(it => it.url === adjustmentTypeUrl) if (!adjustmentType) { return res.redirect(`/${nomsId}`) } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustmentForm = AdjustmentsFormFactory.fromRequest(req, adjustmentType) - await adjustmentForm.validate(() => this.prisonerService.getSentencesAndOffences(prisonerDetail.bookingId, token)) + await adjustmentForm.validate(() => this.prisonerService.getSentencesAndOffences(bookingId, token)) if (adjustmentForm.errors.length) { return res.render('pages/adjustments/form', { - model: { prisonerDetail, form: adjustmentForm, addOrEdit, id }, + model: { form: adjustmentForm, addOrEdit, id }, }) } - const adjustment = adjustmentForm.toAdjustment(prisonerDetail, nomsId, id) + const adjustment = adjustmentForm.toAdjustment(res.locals.prisoner, nomsId, id) const messages = await this.adjustmentsService.validate(adjustment, token) @@ -204,7 +191,7 @@ export default class AdjustmentRoutes { if (validationMessages.length) { adjustmentForm.addErrors(validationMessages) return res.render('pages/adjustments/form', { - model: { prisonerDetail, form: adjustmentForm, addOrEdit, id }, + model: { form: adjustmentForm, addOrEdit, id }, }) } @@ -219,13 +206,11 @@ export default class AdjustmentRoutes { } public review: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) if (this.adjustmentsStoreService.getOnly(req, nomsId)) { return res.render('pages/adjustments/review', { - model: new ReviewModel(prisonerDetail, this.adjustmentsStoreService.getOnly(req, nomsId)), + model: new ReviewModel(this.adjustmentsStoreService.getOnly(req, nomsId)), }) } return res.redirect(`/${nomsId}`) @@ -253,16 +238,15 @@ export default class AdjustmentRoutes { } public warning: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustment = this.adjustmentsStoreService.getOnly(req, nomsId) if (adjustment) { const warning = (await this.adjustmentsService.validate(adjustment, token)).find(it => it.type === 'WARNING') if (warning) { return res.render('pages/adjustments/warning', { - model: new WarningModel(prisonerDetail, adjustment, warning, new WarningForm({})), + model: new WarningModel(adjustment, warning, new WarningForm({})), }) } } @@ -270,7 +254,7 @@ export default class AdjustmentRoutes { } public submitWarning: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params const warningForm = new WarningForm(req.body) @@ -280,11 +264,10 @@ export default class AdjustmentRoutes { const adjustment = this.adjustmentsStoreService.getOnly(req, nomsId) if (adjustment) { if (warningForm.errors.length) { - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) if (adjustment) { const warning = (await this.adjustmentsService.validate(adjustment, token)).find(it => it.type === 'WARNING') return res.render('pages/adjustments/warning', { - model: new WarningModel(prisonerDetail, adjustment, warning, warningForm), + model: new WarningModel(adjustment, warning, warningForm), }) } } @@ -298,17 +281,14 @@ export default class AdjustmentRoutes { } public view: RequestHandler = async (req, res): Promise => { - const { caseloads, token, roles } = res.locals.user + const { token, roles } = res.locals.user const { nomsId, adjustmentTypeUrl } = req.params + const { bookingId } = res.locals.prisoner const adjustmentType = adjustmentTypes.find(it => it.url === adjustmentTypeUrl) if (!adjustmentType) { return res.redirect(`/${nomsId}`) } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope( - prisonerDetail.bookingId, - token, - ) + const startOfSentenceEnvelope = await this.prisonerService.getStartOfSentenceEnvelope(bookingId, token) const adjustments = await this.adjustmentsService.findByPerson( nomsId, startOfSentenceEnvelope.earliestSentence, @@ -319,21 +299,20 @@ export default class AdjustmentRoutes { ? await this.identifyRemandPeriodsService.getRemandDecision(nomsId, token) : null return res.render('pages/adjustments/view', { - model: new ViewModel(prisonerDetail, adjustments, adjustmentType, remandDecision, roles), + model: new ViewModel(adjustments, adjustmentType, remandDecision, roles), }) } public remove: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, adjustmentTypeUrl, id } = req.params const adjustmentType = adjustmentTypes.find(it => it.url === adjustmentTypeUrl) if (!adjustmentType) { return res.redirect(`/${nomsId}`) } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustment = await this.adjustmentsService.get(id, token) return res.render('pages/adjustments/remove', { - model: new RemoveModel(prisonerDetail, adjustment, adjustmentType), + model: new RemoveModel(adjustment, adjustmentType), }) } @@ -361,30 +340,27 @@ export default class AdjustmentRoutes { } public recall: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustments = await this.adjustmentsService.findByPersonAndStatus(nomsId, 'INACTIVE_WHEN_DELETED', token) return res.render('pages/adjustments/recall', { - model: new RecallModel(prisonerDetail, adjustments, new RecallForm({})), + model: new RecallModel(adjustments, new RecallForm({})), }) } public recallSubmit: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params const recallForm = new RecallForm(req.body) await recallForm.validate() if (recallForm.errors.length) { - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustments = await this.adjustmentsService.findByPersonAndStatus(nomsId, 'INACTIVE_WHEN_DELETED', token) return res.render('pages/adjustments/recall', { - model: new RecallModel(prisonerDetail, adjustments, recallForm), + model: new RecallModel(adjustments, recallForm), }) } await this.adjustmentsService.restore({ ids: recallForm.getSelectedAdjustments() }, token) diff --git a/server/routes/remandRoutes.test.ts b/server/routes/remandRoutes.test.ts index 0e827beb..3bc3dfc4 100644 --- a/server/routes/remandRoutes.test.ts +++ b/server/routes/remandRoutes.test.ts @@ -4,11 +4,7 @@ import request from 'supertest' import { appWithAllRoutes } from './testutils/appSetup' import PrisonerService from '../services/prisonerService' import AdjustmentsService from '../services/adjustmentsService' -import { - PrisonApiOffence, - PrisonApiOffenderSentenceAndOffences, - PrisonApiPrisoner, -} from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffence, PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import AdjustmentsStoreService from '../services/adjustmentsStoreService' import './testutils/toContainInOrder' import CalculateReleaseDatesService from '../services/calculateReleaseDatesService' @@ -32,15 +28,6 @@ const NOMS_ID = 'ABC123' const SESSION_ID = '123-abc' const ADJUSTMENT_ID = '9991' -const stubbedPrisonerData = { - offenderNo: NOMS_ID, - firstName: 'Anon', - lastName: 'Nobody', - dateOfBirth: '24/06/2000', - bookingId: 12345, - agencyId: 'LDS', -} as PrisonApiPrisoner - const sentenceAndOffenceBaseRecord = { terms: [ { @@ -87,7 +74,7 @@ const offencesWithoutStartDates: PrisonApiOffence[] = [ const blankAdjustment = { person: NOMS_ID, - bookingId: stubbedPrisonerData.bookingId, + bookingId: 12345, adjustmentType: 'REMAND', } as SessionAdjustment @@ -134,7 +121,6 @@ afterEach(() => { describe('Remand routes tests', () => { it('GET /{nomsId}/remand/add okay', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.store.mockReturnValue(SESSION_ID) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) return request(app) @@ -144,7 +130,6 @@ describe('Remand routes tests', () => { }) it('GET /{nomsId}/remand/add no applicable', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue([]) return request(app) .get(`/${NOMS_ID}/remand/add`) @@ -153,7 +138,6 @@ describe('Remand routes tests', () => { }) it('GET /{nomsId}/remand/no-applicable-sentences', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .get(`/${NOMS_ID}/remand/no-applicable-sentences`) .expect('Content-Type', /html/) @@ -168,7 +152,6 @@ describe('Remand routes tests', () => { it('GET /{nomsId}/remand/dates/add', () => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) return request(app) @@ -190,7 +173,6 @@ describe('Remand routes tests', () => { ${'add'} | ${`/${NOMS_ID}/remand/offences/add/${SESSION_ID}`} ${'edit'} | ${`/${NOMS_ID}/remand/edit/${SESSION_ID}`} `('POST of dates when content is valid redirects correctly', async ({ addOrEdit, redirectLocation }) => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.validate.mockResolvedValue([]) @@ -217,7 +199,6 @@ describe('Remand routes tests', () => { `('POST /{nomsId}/remand/dates/add empty form validation', async ({ addOrEdit }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -237,7 +218,6 @@ describe('Remand routes tests', () => { `('POST /{nomsId}/remand/dates/addOrEdit to date after from', async ({ addOrEdit }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -266,7 +246,6 @@ describe('Remand routes tests', () => { `('POST /{nomsId}/remand/dates/:addOrEdit dates in future', async ({ addOrEdit }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -296,7 +275,6 @@ describe('Remand routes tests', () => { `('POST /{nomsId}/remand/dates/addOrEdit fromDate before earliest offence date', async ({ addOrEdit }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -327,7 +305,6 @@ describe('Remand routes tests', () => { async ({ addOrEdit }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -363,7 +340,6 @@ describe('Remand routes tests', () => { async ({ addOrEdit, redirectLocation }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -429,7 +405,6 @@ describe('Remand routes tests', () => { ])('POST /{nomsId}/remand/dates/addOrEdit overlapping remand periods', ({ adjustment, from, to, id }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([adjustment, { ...adjustment, id }]) @@ -464,7 +439,6 @@ describe('Remand routes tests', () => { `('GET /{nomsId}/remand/offences/:addOrEdit', async ({ addOrEdit, title, backLink }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsStoreService.getById.mockReturnValue(adjustmentWithDates) return request(app) @@ -492,7 +466,6 @@ describe('Remand routes tests', () => { ${'add'} | ${`/${NOMS_ID}/remand/review`} ${'edit'} | ${`/${NOMS_ID}/remand/edit/${SESSION_ID}`} `('POST /{nomsId}/remand/offence/:addOrEdit valid', async ({ addOrEdit, redirectLocation }) => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue(adjustmentWithDates) return request(app) .post(`/${NOMS_ID}/remand/offences/${addOrEdit}/${SESSION_ID}`) @@ -509,7 +482,6 @@ describe('Remand routes tests', () => { ${'add'} ${'edit'} `('POST /{nomsId}/remand/offence/:addOrEdit no offences selected', async ({ addOrEdit }) => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsStoreService.getById.mockReturnValue(adjustmentWithDates) return request(app) @@ -525,7 +497,6 @@ describe('Remand routes tests', () => { it('GET /{nomsId}/remand/review', () => { const adjustments: Record = {} adjustments[SESSION_ID] = adjustmentWithDatesAndCharges - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) calculateReleaseDatesService.calculateUnusedDeductions.mockResolvedValue({ @@ -587,7 +558,6 @@ describe('Remand routes tests', () => { it('POST /{nomsId}/remand/review nothing selected', () => { const adjustments: Record = {} adjustments[SESSION_ID] = adjustmentWithDatesAndCharges - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsStoreService.getAll.mockReturnValue(adjustments) return request(app) @@ -601,7 +571,6 @@ describe('Remand routes tests', () => { it('GET /{nomsId}/remand/save calculated deductions', () => { const adjustments: Record = {} adjustments[SESSION_ID] = adjustmentWithDatesAndCharges - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPerson.mockResolvedValue([]) calculateReleaseDatesService.unusedDeductionsHandlingCRDError.mockResolvedValue( @@ -624,7 +593,6 @@ describe('Remand routes tests', () => { it('GET /{nomsId}/remand/save error from deductions', () => { const adjustments: Record = {} adjustments[SESSION_ID] = adjustmentWithDatesAndCharges - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPerson.mockResolvedValue([]) calculateReleaseDatesService.calculateUnusedDeductions.mockRejectedValue({ error: 'an error' }) @@ -641,7 +609,6 @@ describe('Remand routes tests', () => { const adjustments: Record = {} adjustments[SESSION_ID] = adjustmentWithDatesAndCharges adjustmentsStoreService.getAll.mockReturnValue(adjustments) - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/remand/save`) .expect(302) @@ -649,7 +616,6 @@ describe('Remand routes tests', () => { }) it('GET /{nomsId}/remand/remove', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([adjustmentWithDatesAndCharges]) @@ -672,7 +638,6 @@ describe('Remand routes tests', () => { }) it('POST /{nomsId}/remand/remove', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges) @@ -683,7 +648,6 @@ describe('Remand routes tests', () => { }) it('GET /{nomsId}/remand/edit with successful unused deductions calculation', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -706,7 +670,6 @@ describe('Remand routes tests', () => { }) it('GET /{nomsId}/remand/edit unused deductions calculation errors', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) @@ -725,7 +688,6 @@ describe('Remand routes tests', () => { it('GET /{nomsId}/remand/dates/edit', () => { const adjustments = {} adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges) - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getAll.mockReturnValue(adjustments) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) return request(app) @@ -753,7 +715,6 @@ describe('Remand routes tests', () => { it('GET /{nomsId}/remand/edit with CRD error', () => { const adjustments: Record = {} adjustments[SESSION_ID] = adjustmentWithDatesAndCharges - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([]) adjustmentsStoreService.getById.mockReturnValue(adjustmentWithDatesAndCharges) diff --git a/server/routes/remandRoutes.ts b/server/routes/remandRoutes.ts index 23bde5e1..f7b8f69e 100644 --- a/server/routes/remandRoutes.ts +++ b/server/routes/remandRoutes.ts @@ -25,13 +25,10 @@ export default class RemandRoutes { ) {} public add: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetails = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetails.bookingId, - token, - ) + const { bookingId, agencyId } = res.locals.prisoner + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) if (!sentencesAndOffences.length) { return res.redirect(`/${nomsId}/remand/no-applicable-sentences`) @@ -39,16 +36,16 @@ export default class RemandRoutes { const sessionId = this.adjustmentsStoreService.store(req, nomsId, null, { adjustmentType: 'REMAND', - bookingId: prisonerDetails.bookingId, + bookingId, person: nomsId, - prisonId: prisonerDetails.agencyId, + prisonId: agencyId, }) return res.redirect(`/${nomsId}/remand/dates/add/${sessionId}`) } public dates: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user const { nomsId, addOrEdit, id } = req.params + const { offenderNo } = res.locals.prisoner if (!['edit', 'add'].includes(addOrEdit)) { throw FullPageError.notFoundError() @@ -56,31 +53,28 @@ export default class RemandRoutes { const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) const adjustments = Object.values(this.adjustmentsStoreService.getAll(req, nomsId)) - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const form = RemandDatesForm.fromAdjustment(adjustment) return res.render('pages/adjustments/remand/dates', { - model: new RemandDatesModel(id, prisonerDetail, adjustments, form, addOrEdit), + model: new RemandDatesModel(id, offenderNo, adjustments, form, addOrEdit), }) } public submitDates: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, addOrEdit, id } = req.params - - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId, offenderNo } = res.locals.prisoner const adjustmentForm = new RemandDatesForm({ ...req.body, isEdit: addOrEdit === 'edit', adjustmentId: id }) await adjustmentForm.validate( - () => this.prisonerService.getSentencesAndOffencesFilteredForRemand(prisonerDetail.bookingId, token), + () => this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token), () => this.adjustmentsService.findByPersonOutsideSentenceEnvelope(nomsId, token), ) const sessionAdjustment = this.adjustmentsStoreService.getById(req, nomsId, id) if (adjustmentForm.errors.length) { return res.render('pages/adjustments/remand/dates', { - model: new RemandDatesModel(id, prisonerDetail, [sessionAdjustment], adjustmentForm, addOrEdit), + model: new RemandDatesModel(id, offenderNo, [sessionAdjustment], adjustmentForm, addOrEdit), }) } @@ -97,49 +91,42 @@ export default class RemandRoutes { } public offences: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, addOrEdit, id } = req.params - + const { bookingId, offenderNo } = res.locals.prisoner if (!['edit', 'add'].includes(addOrEdit)) { throw FullPageError.notFoundError() } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) const form = RemandOffencesForm.fromAdjustment(adjustment, sentencesAndOffences) return res.render('pages/adjustments/remand/offences', { - model: new RemandSelectOffencesModel(id, prisonerDetail, adjustment, form, sentencesAndOffences, addOrEdit), + model: new RemandSelectOffencesModel(id, offenderNo, adjustment, form, sentencesAndOffences, addOrEdit), }) } public submitOffences: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, addOrEdit, id } = req.params + const { bookingId, offenderNo } = res.locals.prisoner if (!['edit', 'add'].includes(addOrEdit)) { throw FullPageError.notFoundError() } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const adjustmentForm = new RemandOffencesForm(req.body) await adjustmentForm.validate() const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) if (adjustmentForm.errors.length) { - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) return res.render('pages/adjustments/remand/offences', { model: new RemandSelectOffencesModel( id, - prisonerDetail, + offenderNo, adjustment, adjustmentForm, sentencesAndOffences, @@ -158,8 +145,9 @@ export default class RemandRoutes { } public review: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params + const { bookingId, offenderNo } = res.locals.prisoner const sessionAdjustments = this.adjustmentsStoreService.getAll(req, nomsId) Object.keys(sessionAdjustments).forEach(it => { @@ -171,11 +159,7 @@ export default class RemandRoutes { if (!Object.keys(sessionAdjustments).length) { return res.redirect(`/${nomsId}`) } - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) const adjustments = await this.adjustmentsService.findByPersonOutsideSentenceEnvelope(nomsId, token) const unusedDeductions = await this.calculateReleaseDatesService.unusedDeductionsHandlingCRDError( sessionAdjustments, @@ -187,7 +171,7 @@ export default class RemandRoutes { return res.render('pages/adjustments/remand/review', { model: new RemandReviewModel( - prisonerDetail, + offenderNo, sessionAdjustments, sentencesAndOffences, unusedDeductions?.validationMessages || [], @@ -197,19 +181,16 @@ export default class RemandRoutes { } public submitReview: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params + const { bookingId, offenderNo } = res.locals.prisoner const form = new ReviewRemandForm(req.body) await form.validate() if (form.errors.length) { const sessionAdjustments = this.adjustmentsStoreService.getAll(req, nomsId) const adjustments = await this.adjustmentsService.findByPersonOutsideSentenceEnvelope(nomsId, token) - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) const unusedDeductions = await this.calculateReleaseDatesService.unusedDeductionsHandlingCRDError( sessionAdjustments, adjustments, @@ -219,7 +200,7 @@ export default class RemandRoutes { ) return res.render('pages/adjustments/remand/review', { model: new RemandReviewModel( - prisonerDetail, + offenderNo, sessionAdjustments, sentencesAndOffences, unusedDeductions?.validationMessages || [], @@ -234,15 +215,11 @@ export default class RemandRoutes { } public save: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId } = res.locals.prisoner const sessionAdjustments = this.adjustmentsStoreService.getAll(req, nomsId) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) const adjustments = await this.adjustmentsService.findByPersonOutsideSentenceEnvelope(nomsId, token) const unusedDeductions = await this.calculateReleaseDatesService.unusedDeductionsHandlingCRDError( @@ -254,7 +231,7 @@ export default class RemandRoutes { ) return res.render('pages/adjustments/remand/save', { - model: new RemandSaveModel(prisonerDetail, Object.values(sessionAdjustments), unusedDeductions?.unusedDeductions), + model: new RemandSaveModel(Object.values(sessionAdjustments), unusedDeductions?.unusedDeductions), }) } @@ -280,31 +257,25 @@ export default class RemandRoutes { public view: RequestHandler = async (req, res): Promise => { const { nomsId } = req.params - const { caseloads, token } = res.locals.user - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { token } = res.locals.user + const { bookingId } = res.locals.prisoner const adjustments = (await this.adjustmentsService.findByPersonOutsideSentenceEnvelope(nomsId, token)).filter( it => it.adjustmentType === 'REMAND', ) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) this.adjustmentsStoreService.clear(req, nomsId) return res.render('pages/adjustments/remand/view', { - model: new RemandViewModel(prisonerDetail, adjustments, sentencesAndOffences), + model: new RemandViewModel(adjustments, sentencesAndOffences), }) } public remove: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, id } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId } = res.locals.prisoner const adjustment = await this.adjustmentsService.get(id, token) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) const adjustments = await this.adjustmentsService.getAdjustmentsExceptOneBeingEdited( { [id]: adjustment }, @@ -326,27 +297,18 @@ export default class RemandRoutes { ) return res.render('pages/adjustments/remand/remove', { - model: new RemandChangeModel( - prisonerDetail, - adjustment, - sentencesAndOffences, - unusedDeductions, - showUnusedMessage, - ), + model: new RemandChangeModel(adjustment, sentencesAndOffences, unusedDeductions, showUnusedMessage), }) } public edit: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, id } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId } = res.locals.prisoner let sessionAdjustment = this.adjustmentsStoreService.getById(req, nomsId, id) sessionAdjustment = sessionAdjustment || (await this.adjustmentsService.get(id, token)) this.adjustmentsStoreService.store(req, nomsId, id, sessionAdjustment) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand( - prisonerDetail.bookingId, - token, - ) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(bookingId, token) const adjustments = await this.adjustmentsService.getAdjustmentsExceptOneBeingEdited( { [id]: sessionAdjustment }, nomsId, @@ -368,7 +330,6 @@ export default class RemandRoutes { return res.render('pages/adjustments/remand/edit', { model: new RemandChangeModel( - prisonerDetail, { ...sessionAdjustment, daysTotal: daysBetween(new Date(sessionAdjustment.fromDate), new Date(sessionAdjustment.toDate)), @@ -395,14 +356,6 @@ export default class RemandRoutes { } public noApplicableSentences: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user - const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - - return res.render('pages/adjustments/remand/no-applicable-sentence', { - model: { - prisonerDetail, - }, - }) + return res.render('pages/adjustments/remand/no-applicable-sentence') } } diff --git a/server/routes/taggedBailRoutes.test.ts b/server/routes/taggedBailRoutes.test.ts index 42e33cc8..21dc6d35 100644 --- a/server/routes/taggedBailRoutes.test.ts +++ b/server/routes/taggedBailRoutes.test.ts @@ -6,7 +6,7 @@ import AdjustmentsService from '../services/adjustmentsService' import AdjustmentsStoreService from '../services/adjustmentsStoreService' import './testutils/toContainInOrder' import CalculateReleaseDatesService from '../services/calculateReleaseDatesService' -import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import SessionAdjustment from '../@types/AdjustmentTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' @@ -23,15 +23,6 @@ const adjustmentsStoreService = new AdjustmentsStoreService() as jest.Mocked { describe('Tagged bail routes tests', () => { it('GET /{nomsId}/tagged-bail/add redirects correctly', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.store.mockReturnValue(SESSION_ID) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) return request(app) @@ -130,7 +120,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/select-case/add shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) return request(app) @@ -144,7 +133,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/days/add shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) return request(app) @@ -156,7 +144,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/view DPS adjustment shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([populatedAdjustment]) return request(app) @@ -170,7 +157,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/view NOMIS adjustment shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPersonOutsideSentenceEnvelope.mockResolvedValue([nomisAdjustment]) return request(app) @@ -184,7 +170,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/remove shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPerson.mockResolvedValue([populatedAdjustment]) adjustmentsService.get.mockResolvedValue(populatedAdjustment) @@ -199,7 +184,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/remove shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPerson.mockResolvedValue([nomisAdjustment]) adjustmentsService.get.mockResolvedValue(populatedAdjustment) @@ -214,7 +198,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/remove shows unused deductions message', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsService.findByPerson.mockResolvedValue([populatedAdjustment]) adjustmentsService.get.mockResolvedValue(populatedAdjustment) @@ -237,7 +220,6 @@ describe('Tagged bail routes tests', () => { }) it('GET /{nomsId}/tagged-bail/review/add shows correct information', () => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences) adjustmentsStoreService.getById.mockReturnValue(populatedAdjustment) @@ -255,7 +237,6 @@ describe('Tagged bail routes tests', () => { const adjustments: Record = {} adjustments[SESSION_ID] = populatedAdjustment adjustmentsStoreService.getById.mockReturnValue(populatedAdjustment) - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) return request(app) .post(`/${NOMS_ID}/tagged-bail/review/add/${SESSION_ID}`) .expect(302) @@ -271,7 +252,6 @@ describe('Tagged bail routes tests', () => { async ({ addOrEdit, complete, backLink, selectHref }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue({ ...populatedAdjustment, complete }) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) @@ -292,7 +272,6 @@ describe('Tagged bail routes tests', () => { `('GET /{nomsId}/tagged-bail/days/:addOrEdit back link tests', async ({ addOrEdit, complete, backLink }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue({ ...populatedAdjustment, complete }) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences) @@ -307,7 +286,6 @@ describe('Tagged bail routes tests', () => { it('GET /{nomsId}/tagged-bail/review/select-case/add/:id shows selected if a record has already been chosen', () => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue({ ...populatedAdjustment, complete: true }) prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffencesWithSelected) @@ -325,7 +303,6 @@ describe('POST /{nomsId}/tagged-bail/days/:addOrEdit validation tests', () => { addOrEdit | redirectLocation ${'add'} | ${`/${NOMS_ID}/tagged-bail/review/add/${SESSION_ID}`} `('POST of days when content is valid redirects correctly', async ({ addOrEdit, redirectLocation }) => { - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) adjustmentsService.validate.mockResolvedValue([]) return request(app) @@ -343,7 +320,6 @@ describe('POST /{nomsId}/tagged-bail/days/:addOrEdit validation tests', () => { `('POST /{nomsId}/tagged-bail/dates/add empty form validation', async ({ addOrEdit }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) return request(app) .post(`/${NOMS_ID}/tagged-bail/days/${addOrEdit}/${SESSION_ID}`) @@ -364,7 +340,6 @@ describe('POST /{nomsId}/tagged-bail/days/:addOrEdit validation tests', () => { `('POST /{nomsId}/tagged-bail/dates/:addOrEdit invalid number entered for days', async ({ addOrEdit, days }) => { const adjustments: Record = {} adjustments[SESSION_ID] = blankAdjustment - prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) adjustmentsStoreService.getById.mockReturnValue(blankAdjustment) return request(app) .post(`/${NOMS_ID}/tagged-bail/days/${addOrEdit}/${SESSION_ID}`) diff --git a/server/routes/taggedBailRoutes.ts b/server/routes/taggedBailRoutes.ts index 939ced0b..8d3701e0 100644 --- a/server/routes/taggedBailRoutes.ts +++ b/server/routes/taggedBailRoutes.ts @@ -27,37 +27,35 @@ export default class TaggedBailRoutes { ) {} public add: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId, agencyId } = res.locals.prisoner const sessionId = this.adjustmentsStoreService.store(req, nomsId, null, { adjustmentType: 'TAGGED_BAIL', - bookingId: prisonerDetail.bookingId, + bookingId, person: nomsId, - prisonId: prisonerDetail.agencyId, + prisonId: agencyId, }) return res.redirect(`/${nomsId}/tagged-bail/select-case/add/${sessionId}`) } public selectCase: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, addOrEdit, id } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(prisonerDetail.bookingId, token) + const { bookingId, offenderNo } = res.locals.prisoner + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(bookingId, token) const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) return res.render('pages/adjustments/tagged-bail/select-case', { - model: new TaggedBailSelectCaseModel(prisonerDetail, sentencesAndOffences, addOrEdit, id, adjustment), + model: new TaggedBailSelectCaseModel(offenderNo, sentencesAndOffences, addOrEdit, id, adjustment), }) } public days: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user const { nomsId, addOrEdit, id } = req.params const { caseSequence } = req.query as Record - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { offenderNo } = res.locals.prisoner const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) if (caseSequence) { this.adjustmentsStoreService.store(req, nomsId, id, { @@ -68,21 +66,19 @@ export default class TaggedBailRoutes { const form = TaggedBailDaysForm.fromAdjustment(adjustment) return res.render('pages/adjustments/tagged-bail/days', { - model: new TaggedBailDaysModel(prisonerDetail, addOrEdit, id, form, adjustment), + model: new TaggedBailDaysModel(offenderNo, addOrEdit, id, form, adjustment), }) } public submitDays: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user const { nomsId, addOrEdit, id } = req.params - - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { offenderNo } = res.locals.prisoner const adjustmentForm = new TaggedBailDaysForm({ ...req.body, isEdit: addOrEdit === 'edit', adjustmentId: id }) const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) await adjustmentForm.validate() if (adjustmentForm.errors.length) { return res.render('pages/adjustments/tagged-bail/days', { - model: new TaggedBailDaysModel(prisonerDetail, addOrEdit, id, adjustmentForm, adjustment), + model: new TaggedBailDaysModel(offenderNo, addOrEdit, id, adjustmentForm, adjustment), }) } @@ -91,9 +87,9 @@ export default class TaggedBailRoutes { } public view: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId, offenderNo } = res.locals.prisoner const adjustments = await this.adjustmentsService.findByPersonOutsideSentenceEnvelope(nomsId, token) const taggedBailAdjustments = adjustments.filter(it => it.adjustmentType === 'TAGGED_BAIL') if (!taggedBailAdjustments.length) { @@ -105,17 +101,17 @@ export default class TaggedBailRoutes { return res.redirect(`/${nomsId}`) } - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(prisonerDetail.bookingId, token) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(bookingId, token) return res.render('pages/adjustments/tagged-bail/view', { - model: new TaggedBailViewModel(prisonerDetail, taggedBailAdjustments, adjustmentType, sentencesAndOffences), + model: new TaggedBailViewModel(offenderNo, taggedBailAdjustments, adjustmentType, sentencesAndOffences), }) } public remove: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, id } = req.params - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId, offenderNo } = res.locals.prisoner const adjustment = await this.adjustmentsService.get(id, token) if (!adjustment) { return res.redirect(`/${nomsId}`) @@ -126,7 +122,7 @@ export default class TaggedBailRoutes { return res.redirect(`/${nomsId}`) } - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(prisonerDetail.bookingId, token) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(bookingId, token) const sentencesByCaseSequence = getActiveSentencesByCaseSequence(sentencesAndOffences) const sentencesForCaseSequence = sentencesByCaseSequence.find(it => relevantSentenceForTaggedBailAdjustment(it, adjustment), @@ -154,21 +150,15 @@ export default class TaggedBailRoutes { ) return res.render('pages/adjustments/tagged-bail/remove', { - model: new TaggedBailRemoveModel( - prisonerDetail, - adjustment, - adjustmentType, - sentenceAndOffence, - showUnusedMessage, - ), + model: new TaggedBailRemoveModel(offenderNo, adjustment, adjustmentType, sentenceAndOffence, showUnusedMessage), }) } public review: RequestHandler = async (req, res): Promise => { - const { caseloads, token } = res.locals.user + const { token } = res.locals.user const { nomsId, addOrEdit, id } = req.params const { caseSequence } = req.query as Record - const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) + const { bookingId, offenderNo } = res.locals.prisoner if (caseSequence) { this.adjustmentsStoreService.store(req, nomsId, id, { ...this.adjustmentsStoreService.getById(req, nomsId, id), @@ -176,10 +166,10 @@ export default class TaggedBailRoutes { }) } const adjustment = this.adjustmentsStoreService.getById(req, nomsId, id) - const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(prisonerDetail.bookingId, token) + const sentencesAndOffences = await this.prisonerService.getSentencesAndOffences(bookingId, token) return res.render('pages/adjustments/tagged-bail/review', { - model: new TaggedBailReviewModel(prisonerDetail, addOrEdit, id, sentencesAndOffences, adjustment), + model: new TaggedBailReviewModel(offenderNo, addOrEdit, id, sentencesAndOffences, adjustment), }) } diff --git a/server/routes/testutils/appSetup.ts b/server/routes/testutils/appSetup.ts index 61857598..f9f2d79b 100644 --- a/server/routes/testutils/appSetup.ts +++ b/server/routes/testutils/appSetup.ts @@ -8,6 +8,7 @@ import errorHandler from '../../errorHandler' import * as auth from '../../authentication/auth' import type { Services } from '../../services' import type { ApplicationInfo } from '../../applicationInfo' +import { PrisonApiPrisoner } from '../../@types/prisonApi/prisonClientTypes' const testAppInfo: ApplicationInfo = { applicationName: 'test', @@ -17,6 +18,15 @@ const testAppInfo: ApplicationInfo = { branchName: 'main', } +const defaultPrisoner: PrisonApiPrisoner = { + offenderNo: 'ABC123', + firstName: 'Anon', + lastName: 'Nobody', + dateOfBirth: '24/06/2000', + bookingId: 12345, + agencyId: 'LDS', +} + export const user: Express.User = { name: 'FIRST LAST', userId: 'id', @@ -31,7 +41,12 @@ export const user: Express.User = { export const flashProvider = jest.fn() -function appSetup(services: Services, production: boolean, userSupplier: () => Express.User): Express { +function appSetup( + services: Services, + production: boolean, + userSupplier: () => Express.User, + prisoner: PrisonApiPrisoner, +): Express { const app = express() app.set('view engine', 'njk') @@ -43,6 +58,7 @@ function appSetup(services: Services, production: boolean, userSupplier: () => E req.flash = flashProvider res.locals = { user: { ...req.user }, + prisoner, } next() }) @@ -59,11 +75,13 @@ export function appWithAllRoutes({ production = false, services = {}, userSupplier = () => user, + prisoner = defaultPrisoner, }: { production?: boolean services?: Partial userSupplier?: () => Express.User + prisoner?: PrisonApiPrisoner }): Express { auth.default.authenticationMiddleware = () => (req, res, next) => next() - return appSetup(services as Services, production, userSupplier) + return appSetup(services as Services, production, userSupplier, prisoner) } diff --git a/server/services/additionalDaysAwardedService.test.ts b/server/services/additionalDaysAwardedService.test.ts index cd821b13..a9f9a334 100644 --- a/server/services/additionalDaysAwardedService.test.ts +++ b/server/services/additionalDaysAwardedService.test.ts @@ -760,7 +760,6 @@ describe('Additional Days Added Service', () => { }) it('Should intercept mix of concurrent consec', async () => { const nomsId = 'AA1234A' - const bookingId = 1234 prisonApi.get('/api/offenders/AA1234A/adjudications', '').reply(200, threeAdjudicationsSearchResponse) prisonApi.get('/api/offenders/AA1234A/adjudications/1525916', '').reply(200, adjudicationOne) prisonApi.get('/api/offenders/AA1234A/adjudications/1525917', '').reply(200, adjudicationTwoConsecutiveToOne) @@ -768,16 +767,7 @@ describe('Additional Days Added Service', () => { const startOfSentenceEnvelope = new Date('2023-01-01') const request = {} as jest.Mocked storeService.getLastApprovedDate.mockReturnValue(null) - const intercept = await adaService.shouldIntercept( - request, - { - offenderNo: nomsId, - bookingId, - } as PrisonApiPrisoner, - [], - startOfSentenceEnvelope, - token, - ) + const intercept = await adaService.shouldIntercept(request, nomsId, [], startOfSentenceEnvelope, token) expect(intercept).toEqual({ type: 'UPDATE', @@ -787,7 +777,6 @@ describe('Additional Days Added Service', () => { }) it('Shouldnt intercept when already persisted in adjustment api', async () => { const nomsId = 'AA1234A' - const bookingId = 1234 prisonApi.get('/api/offenders/AA1234A/adjudications', '').reply(200, threeAdjudicationsSearchResponse) prisonApi.get('/api/offenders/AA1234A/adjudications/1525916', '').reply(200, adjudicationOne) prisonApi.get('/api/offenders/AA1234A/adjudications/1525917', '').reply(200, adjudicationTwoConsecutiveToOne) @@ -797,10 +786,7 @@ describe('Additional Days Added Service', () => { storeService.getLastApprovedDate.mockReturnValue(null) const intercept = await adaService.shouldIntercept( request, - { - offenderNo: nomsId, - bookingId, - } as PrisonApiPrisoner, + nomsId, [ { person: 'AA1234A', @@ -824,7 +810,6 @@ describe('Additional Days Added Service', () => { it('Should intercept when already persisted adjustment has different days', async () => { const nomsId = 'AA1234A' - const bookingId = 1234 prisonApi.get('/api/offenders/AA1234A/adjudications', '').reply(200, threeAdjudicationsSearchResponse) prisonApi.get('/api/offenders/AA1234A/adjudications/1525916', '').reply(200, adjudicationOne) prisonApi.get('/api/offenders/AA1234A/adjudications/1525917', '').reply(200, adjudicationTwoConsecutiveToOne) @@ -834,10 +819,7 @@ describe('Additional Days Added Service', () => { storeService.getLastApprovedDate.mockReturnValue(null) const intercept = await adaService.shouldIntercept( request, - { - offenderNo: nomsId, - bookingId, - } as PrisonApiPrisoner, + nomsId, [ { person: 'AA1234A', @@ -860,22 +842,12 @@ describe('Additional Days Added Service', () => { }) it('Shouldnt intercept when recently saved prospective', async () => { const nomsId = 'AA1234A' - const bookingId = 1234 prisonApi.get('/api/offenders/AA1234A/adjudications', '').reply(200, oneAdjudicationSearchResponse) prisonApi.get('/api/offenders/AA1234A/adjudications/1525916', '').reply(200, adjudicationOneProspective) const startOfSentenceEnvelope = new Date('2023-01-01') const request = {} as jest.Mocked storeService.getLastApprovedDate.mockReturnValue(new Date()) - const intercept = await adaService.shouldIntercept( - request, - { - offenderNo: nomsId, - bookingId, - } as PrisonApiPrisoner, - [], - startOfSentenceEnvelope, - 'username', - ) + const intercept = await adaService.shouldIntercept(request, nomsId, [], startOfSentenceEnvelope, 'username') expect(intercept).toEqual({ type: 'NONE', @@ -887,20 +859,10 @@ describe('Additional Days Added Service', () => { it('Shouldnt intercept when there are no non recall sentences', async () => { const nomsId = 'AA1234A' - const bookingId = 1234 const startOfSentenceEnvelope: Date = null const request = {} as jest.Mocked storeService.getLastApprovedDate.mockReturnValue(new Date()) - const intercept = await adaService.shouldIntercept( - request, - { - offenderNo: nomsId, - bookingId, - } as PrisonApiPrisoner, - [], - startOfSentenceEnvelope, - token, - ) + const intercept = await adaService.shouldIntercept(request, nomsId, [], startOfSentenceEnvelope, token) expect(intercept).toEqual({ type: 'NONE', @@ -911,7 +873,6 @@ describe('Additional Days Added Service', () => { it('Should intercept if all adas quashed', async () => { const nomsId = 'AA1234A' - const bookingId = 1234 prisonApi.get('/api/offenders/AA1234A/adjudications', '').reply(200, threeAdjudicationsSearchResponse) prisonApi.get('/api/offenders/AA1234A/adjudications/1525916', '').reply(200, adjudicationOneQuashed) prisonApi.get('/api/offenders/AA1234A/adjudications/1525917', '').reply(200, adjudicationTwoConsecutiveToOneQuashed) @@ -923,10 +884,7 @@ describe('Additional Days Added Service', () => { const intercept = await adaService.shouldIntercept( request, - { - offenderNo: nomsId, - bookingId, - } as PrisonApiPrisoner, + nomsId, [ { id: 'c5b61b4e-8b47-4dfc-b88b-5eb58fc04691', diff --git a/server/services/additionalDaysAwardedService.ts b/server/services/additionalDaysAwardedService.ts index c692330a..fed287dc 100644 --- a/server/services/additionalDaysAwardedService.ts +++ b/server/services/additionalDaysAwardedService.ts @@ -394,7 +394,7 @@ export default class AdditionalDaysAwardedService { public async shouldIntercept( req: Request, - prisonerDetail: PrisonApiPrisoner, + prisonerNumber: string, adjustments: Adjustment[], startOfSentenceEnvelope: Date, token: string, @@ -404,7 +404,7 @@ export default class AdditionalDaysAwardedService { } const allAdaAdjustments = adjustments.filter(it => it.adjustmentType === 'ADDITIONAL_DAYS_AWARDED') - const adas: Ada[] = await this.lookupAdas(token, prisonerDetail.offenderNo, startOfSentenceEnvelope) + const adas: Ada[] = await this.lookupAdas(token, prisonerNumber, startOfSentenceEnvelope) const awardedOrPending: AdasByDateCharged[] = this.getAdasByDateCharged(adas, 'AWARDED_OR_PENDING') const { awaitingApproval, awarded } = this.filterAdasByMatchingAdjustment(awardedOrPending, allAdaAdjustments) @@ -418,7 +418,7 @@ export default class AdditionalDaysAwardedService { return this.shouldInterceptLogic( req, - prisonerDetail.offenderNo, + prisonerNumber, allAdaAdjustments, [...awarded, ...prospectiveAwarded], awaitingApproval, @@ -559,7 +559,7 @@ export default class AdditionalDaysAwardedService { const quashedAdjustments = quashed.map(it => { return allAdaAdjustments.find(adjustment => this.adjustmentMatchesAdjudication(it, adjustment)) }) - return new ReviewAndSubmitAdaViewModel(prisonerDetail, adjustmentsToCreate, allAdaAdjustments, quashedAdjustments) + return new ReviewAndSubmitAdaViewModel(adjustmentsToCreate, allAdaAdjustments, quashedAdjustments) } public async submitAdjustments( diff --git a/server/utils/utils.test.ts b/server/utils/utils.test.ts index cb9aeff1..06c390f3 100644 --- a/server/utils/utils.test.ts +++ b/server/utils/utils.test.ts @@ -99,10 +99,7 @@ describe('Future date tests', () => { describe('Calculate Release Dates Location', () => { it('Check redirection to reason is configured', () => { - const stubbedPrisonerData = { - offenderNo: 'A1234AA', - } - return expect(calculateReleaseDatesCheckInformationUrl(stubbedPrisonerData)).toContain( + return expect(calculateReleaseDatesCheckInformationUrl('A1234AA')).toContain( 'http://localhost:8080/calculation/A1234AA/reason', ) }) diff --git a/server/utils/utils.ts b/server/utils/utils.ts index 258cef12..5e0f923d 100644 --- a/server/utils/utils.ts +++ b/server/utils/utils.ts @@ -1,11 +1,7 @@ import dayjs from 'dayjs' import ValidationError from '../model/validationError' import config from '../config' -import { - PrisonApiOffence, - PrisonApiOffenderSentenceAndOffences, - PrisonApiPrisoner, -} from '../@types/prisonApi/prisonClientTypes' +import { PrisonApiOffence, PrisonApiOffenderSentenceAndOffences } from '../@types/prisonApi/prisonClientTypes' import { Adjustment } from '../@types/adjustments/adjustmentsTypes' import { CalculateReleaseDatesValidationMessage, @@ -99,8 +95,8 @@ export function delay(ms: number): Promise { }) } -export function calculateReleaseDatesCheckInformationUrl(prisonerDetail: PrisonApiPrisoner) { - return `${config.services.calculateReleaseDatesUI.url}/calculation/${prisonerDetail.offenderNo}/reason` +export function calculateReleaseDatesCheckInformationUrl(prisonerNumber: string) { + return `${config.services.calculateReleaseDatesUI.url}/calculation/${prisonerNumber}/reason` } export const fieldsToDate = (day: string, month: string, year: string): Date => diff --git a/server/views/macros/hubAdjustmentCard.njk b/server/views/macros/hubAdjustmentCard.njk index 35bd40d6..fccf6481 100644 --- a/server/views/macros/hubAdjustmentCard.njk +++ b/server/views/macros/hubAdjustmentCard.njk @@ -1,20 +1,20 @@ {% from "govuk/components/details/macro.njk" import govukDetails %} -{% macro adjustmentCard(adjustmentType, model) %} +{% macro adjustmentCard(adjustmentType, model, prisonerNumber) %}

{{ adjustmentType.text }}

  • {% if model.displayAddLink(adjustmentType) %} - Add new {% else %} - Review remand + Review remand {% endif %}
  • {% if model.showDetails(adjustmentType) %}
  • - View
  • {% endif %} @@ -45,7 +45,7 @@
    Reason for rejection: {{ model.remandDecision.rejectComment }}
    - Re-review + Re-review {% endif %}

    {% endif %} diff --git a/server/views/pages/adjustments/additional-days/add-warning.njk b/server/views/pages/adjustments/additional-days/add-warning.njk index 726dee7c..5a2a987f 100644 --- a/server/views/pages/adjustments/additional-days/add-warning.njk +++ b/server/views/pages/adjustments/additional-days/add-warning.njk @@ -7,7 +7,7 @@ {% block content %} - Back + Back
    diff --git a/server/views/pages/adjustments/additional-days/intercept.njk b/server/views/pages/adjustments/additional-days/intercept.njk index 5f3a5563..a8693716 100644 --- a/server/views/pages/adjustments/additional-days/intercept.njk +++ b/server/views/pages/adjustments/additional-days/intercept.njk @@ -18,11 +18,11 @@ {% if model.intercept.type == 'FIRST_TIME' %} The first time you use the adjustments service, you need to check if the existing adjustment information from NOMIS is correct. {% elif model.intercept.type == 'PADA' %} - There is a prospective ADA recorded for {{ model.prisonerDetail.firstName | title }} - {{ model.prisonerDetail.lastName | title }}. + There is a prospective ADA recorded for {{ prisoner.firstName | title }} + {{ prisoner.lastName | title }}. {% elif model.intercept.type == 'UPDATE' %} - Updates have been made to {{ model.prisonerDetail.firstName | title }} - {{ model.prisonerDetail.lastName | title }}'s adjustment information, which need to be approved. + Updates have been made to {{ prisoner.firstName | title }} + {{ prisoner.lastName | title }}'s adjustment information, which need to be approved. {% endif %}

    @@ -42,9 +42,9 @@ {% endif %} {% if model.intercept.anyProspective %} - {% set url = "/" + model.prisonerDetail.offenderNo + "/additional-days/review-prospective" %} + {% set url = "/" + prisoner.offenderNo + "/additional-days/review-prospective" %} {% else %} - {% set url = "/" + model.prisonerDetail.offenderNo + "/additional-days/review-and-approve" %} + {% set url = "/" + prisoner.offenderNo + "/additional-days/review-and-approve" %} {% endif %} Review diff --git a/server/views/pages/adjustments/additional-days/review-and-approve.njk b/server/views/pages/adjustments/additional-days/review-and-approve.njk index e8e7a774..c556e930 100644 --- a/server/views/pages/adjustments/additional-days/review-and-approve.njk +++ b/server/views/pages/adjustments/additional-days/review-and-approve.njk @@ -8,9 +8,9 @@ {% block content %} {% if adasToReview.intercept.anyProspective %} - {% set url = "/" + model.prisonerDetail.offenderNo + "/additional-days/review-prospective" %} + {% set url = "/" + prisoner.offenderNo + "/additional-days/review-prospective" %} {% else %} - {% set url = "/" + model.prisonerDetail.offenderNo + "/additional-days/intercept" %} + {% set url = "/" + prisoner.offenderNo + "/additional-days/intercept" %} {% endif %} Back @@ -37,7 +37,7 @@ adas: adasToReview.awarded, total: adasToReview.totalAwarded, mainTitle: 'Awarded ADAs will be included in the calculation.', - emptyTitle: model.prisonerDetail.firstName | title + ' ' + model.prisonerDetail.lastName | title + ' has no ADAs that are applicable to the current sentences.' + emptyTitle: prisoner.firstName | title + ' ' + prisoner.lastName | title + ' has no ADAs that are applicable to the current sentences.' }) }} {% endif %} diff --git a/server/views/pages/adjustments/additional-days/review-and-submit.njk b/server/views/pages/adjustments/additional-days/review-and-submit.njk index b53eca1e..b991ae1f 100644 --- a/server/views/pages/adjustments/additional-days/review-and-submit.njk +++ b/server/views/pages/adjustments/additional-days/review-and-submit.njk @@ -8,7 +8,7 @@ {% block content %} - {% set backUrl = '/' + model.prisonerDetail.offenderNo + '/additional-days/review-prospective' if referrer==='REVIEW_PROSPECTIVE' else '/' + model.prisonerDetail.offenderNo + '/additional-days/review-and-approve' %} + {% set backUrl = '/' + prisoner.offenderNo + '/additional-days/review-prospective' if referrer==='REVIEW_PROSPECTIVE' else '/' + prisoner.offenderNo + '/additional-days/review-and-approve' %} Back diff --git a/server/views/pages/adjustments/additional-days/review-prospective.njk b/server/views/pages/adjustments/additional-days/review-prospective.njk index 3cf0a505..d20fda71 100644 --- a/server/views/pages/adjustments/additional-days/review-prospective.njk +++ b/server/views/pages/adjustments/additional-days/review-prospective.njk @@ -8,7 +8,7 @@ {% block content %} - Back + Back {% if padaForm.errors.length %}
    diff --git a/server/views/pages/adjustments/additional-days/view.njk b/server/views/pages/adjustments/additional-days/view.njk index e2267d00..d546220f 100644 --- a/server/views/pages/adjustments/additional-days/view.njk +++ b/server/views/pages/adjustments/additional-days/view.njk @@ -7,7 +7,7 @@ {% block content %} - Back + Back
    diff --git a/server/views/pages/adjustments/form.njk b/server/views/pages/adjustments/form.njk index 44b00b5d..336febdc 100644 --- a/server/views/pages/adjustments/form.njk +++ b/server/views/pages/adjustments/form.njk @@ -12,12 +12,12 @@ {{ super() }}

    - This page lists all the adjustments that have been recorded for {{ model.prisonerDetail.firstName | title }} - {{ model.prisonerDetail.lastName | title }}. + This page lists all the adjustments that have been recorded for {{ prisoner.firstName | title }} + {{ prisoner.lastName | title }}. You can add new adjustments or review remand time that has been identified from court outcomes logged in NOMIS.

    @@ -118,10 +118,10 @@

    There is existing remand to review

    Based on the data from court outcomes in - NOMIS, {{ model.prisonerDetail.firstName | title }} - {{ model.prisonerDetail.lastName | title }} may have {{ model.getTotalDaysRelevantRemand() }} days remand. + NOMIS, {{ prisoner.firstName | title }} + {{ prisoner.lastName | title }} may have {{ model.getTotalDaysRelevantRemand() }} days remand. Review the remand to make sure it is relevant.

    - Review
    {% endif %} @@ -131,7 +131,7 @@
    {% for adjustmentType in model.deductions() %} - {{ adjustmentCard(adjustmentType, model) }} + {{ adjustmentCard(adjustmentType, model, prisoner.offenderNo) }} {% endfor %}
    @@ -140,7 +140,7 @@
    {% for adjustmentType in model.additions() %} - {{ adjustmentCard(adjustmentType, model) }} + {{ adjustmentCard(adjustmentType, model, prisoner.offenderNo) }} {% endfor %}
    @@ -148,8 +148,8 @@

    Calculate release dates

    -

    The changes may affect the release date for {{ model.prisonerDetail.firstName | title }} - {{ model.prisonerDetail.lastName | title }} +

    The changes may affect the release date for {{ prisoner.firstName | title }} + {{ prisoner.lastName | title }}

    Calculate release dates diff --git a/server/views/pages/adjustments/recall.njk b/server/views/pages/adjustments/recall.njk index ed8f0b08..9e09cfd7 100644 --- a/server/views/pages/adjustments/recall.njk +++ b/server/views/pages/adjustments/recall.njk @@ -17,8 +17,8 @@

    - This page lists adjustments that have been recorded previously for {{ model.prisonerDetail.firstName | title }} - {{ model.prisonerDetail.lastName | title }}. + This page lists adjustments that have been recorded previously for {{ prisoner.firstName | title }} + {{ prisoner.lastName | title }}. Some of these adjustments may be applicable to recall sentences

    diff --git a/server/views/pages/adjustments/remand/dates.njk b/server/views/pages/adjustments/remand/dates.njk index 7c9c3e98..85d22333 100644 --- a/server/views/pages/adjustments/remand/dates.njk +++ b/server/views/pages/adjustments/remand/dates.njk @@ -90,7 +90,7 @@ {{ govukButton({ text: "Cancel", classes: "govuk-button--secondary", - href: model.backlink() if model.addOrEdit === 'edit' else "/" + model.prisonerDetail.offenderNo + href: model.backlink() if model.addOrEdit === 'edit' else "/" + prisoner.offenderNo }) }}
    diff --git a/server/views/pages/adjustments/remand/edit.njk b/server/views/pages/adjustments/remand/edit.njk index 0dc95297..a0a45866 100644 --- a/server/views/pages/adjustments/remand/edit.njk +++ b/server/views/pages/adjustments/remand/edit.njk @@ -12,7 +12,7 @@ {% endblock %} @@ -53,7 +53,7 @@ {{ remandSummary({ adjustment: model.adjustment, offences: model.listOffences(), - offenderNo: model.prisonerDetail.offenderNo, + offenderNo: prisoner.offenderNo, isEdit: true }) }} @@ -76,7 +76,7 @@ {{ govukButton({ text: "Cancel", - href: "/" + model.prisonerDetail.offenderNo + "/remand/view", + href: "/" + prisoner.offenderNo + "/remand/view", classes: "govuk-button--secondary" }) }}
diff --git a/server/views/pages/adjustments/remand/no-applicable-sentence.njk b/server/views/pages/adjustments/remand/no-applicable-sentence.njk index b9a3a9c8..e7ccc6b2 100644 --- a/server/views/pages/adjustments/remand/no-applicable-sentence.njk +++ b/server/views/pages/adjustments/remand/no-applicable-sentence.njk @@ -7,7 +7,7 @@ {% block content %} - Back + Back
diff --git a/server/views/pages/adjustments/remand/offences.njk b/server/views/pages/adjustments/remand/offences.njk index 98bcaf6a..760abc2b 100644 --- a/server/views/pages/adjustments/remand/offences.njk +++ b/server/views/pages/adjustments/remand/offences.njk @@ -102,7 +102,7 @@ {{ govukButton({ text: "Cancel", classes: "govuk-button--secondary", - href: model.backlink() if model.addOrEdit === 'edit' else "/" + model.prisonerDetail.offenderNo + href: model.backlink() if model.addOrEdit === 'edit' else "/" + prisoner.offenderNo }) }}
diff --git a/server/views/pages/adjustments/remand/remove.njk b/server/views/pages/adjustments/remand/remove.njk index 81bf40b3..a1dd6a93 100644 --- a/server/views/pages/adjustments/remand/remove.njk +++ b/server/views/pages/adjustments/remand/remove.njk @@ -11,7 +11,7 @@ {% endblock %} @@ -26,7 +26,7 @@ {{ remandSummary({ adjustment: model.adjustment, offences: model.listOffences(), - offenderNo: model.prisonerDetail.offenderNo + offenderNo: prisoner.offenderNo }) }}
@@ -47,7 +47,7 @@ {{ govukButton({ text: "Cancel", - href: "/" + model.prisonerDetail.offenderNo + "/remand/view", + href: "/" + prisoner.offenderNo + "/remand/view", classes: "govuk-button--secondary" }) }}
diff --git a/server/views/pages/adjustments/remand/review.njk b/server/views/pages/adjustments/remand/review.njk index cde38fc0..fa4298eb 100644 --- a/server/views/pages/adjustments/remand/review.njk +++ b/server/views/pages/adjustments/remand/review.njk @@ -87,7 +87,7 @@

Remand adjustment

@@ -134,7 +134,7 @@ {{ govukButton({ text: "Cancel", classes: "govuk-button--secondary", - href: "/" + model.prisonerDetail.offenderNo + href: "/" + prisoner.offenderNo }) }}
{% endif %} diff --git a/server/views/pages/adjustments/remand/save.njk b/server/views/pages/adjustments/remand/save.njk index bdf1ec69..be020e6e 100644 --- a/server/views/pages/adjustments/remand/save.njk +++ b/server/views/pages/adjustments/remand/save.njk @@ -14,7 +14,7 @@ {% block beforeContent %} {{ super() }}