Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adjust1-101 view tagged bail adjustment #150

Merged
merged 10 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/@types/adjustments/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export interface components {
*/
prisonId?: string
/**
* @description The name name of the prison where the prisoner was located at the time the adjustment was created
* @description The name of the prison where the prisoner was located at the time the adjustment was created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files are generated by the scripts in /scripts. The scripts generate these files from the backend API docs.

Not a big deal, just an FYI.

https://github.com/ministryofjustice/hmpps-adjustments-api/blob/main/src/main/kotlin/uk/gov/justice/digital/hmpps/adjustments/api/model/AdjustmentDto.kt#L39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've undone that comment change and have adjusted the comment in the Dto instead 👍

* @example Leeds
*/
prisonName?: string
Expand Down
77 changes: 77 additions & 0 deletions server/model/taggedBailViewModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { PrisonApiOffenderSentenceAndOffences, PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes'
import { Adjustment } from '../@types/adjustments/adjustmentsTypes'
import { AdjustmentType } from './adjustmentTypes'

export default class TaggedBailViewModel {
constructor(
public prisonerDetail: PrisonApiPrisoner,
public adjustments: Adjustment[],
public adjustmentType: AdjustmentType,
public sentencesAndOffences: PrisonApiOffenderSentenceAndOffences[],
) {}

public backlink(): string {
return `/${this.prisonerDetail.offenderNo}`
}

public columnHeadings() {
return [{ text: 'Court name' }, { text: 'Case reference' }, { text: 'Days' }, { text: 'Actions' }]
}

public rows() {
return this.adjustments.map(it => {
return [
{ text: this.getCourtName(it.taggedBail.caseSequence) },
{ text: this.getCaseReference(it.taggedBail.caseSequence) },
{ text: it.days || it.daysBetween || it.effectiveDays },
this.actionCell(it),
]
})
}

public table() {
return {
head: this.columnHeadings(),
rows: this.rows().concat(this.totalRow()),
attributes: { 'data-qa': 'view-table' },
}
}

public totalRow() {
const total = this.adjustments.map(it => it.days || it.daysBetween || it.effectiveDays).reduce((a, b) => a + b, 0)
return [[{ html: '<b>Total days</b>' }, { html: '' }, { html: `<b>${total}</b>` }, { text: '' }]]
}

private getCourtName(caseSequence: number): string {
const sentenceAndOffence = this.sentencesAndOffences.find(it => it.caseSequence === caseSequence)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there can be multiple sentences on the same court case (Will have the same case sequence).

Have a look at how we select the sentence by sentence date in the add journey.
https://github.com/ministryofjustice/hmpps-adjustments/blob/main/server/model/taggedBailSelectCaseModel.ts#L32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved some logic out of the taggedBailSelectCaseModel.ts into the utils.ts so that they can be used by the taggedBailViewModel.ts too. This way they're both using the same logic 👍

if (sentenceAndOffence) {
return sentenceAndOffence.courtDescription
}

return null
}

private getCaseReference(caseSequence: number): string {
const sentenceAndOffence = this.sentencesAndOffences.find(it => it.caseSequence === caseSequence)
if (sentenceAndOffence) {
return sentenceAndOffence.caseReference
}

return null
}

private actionCell(adjustment: Adjustment) {
return {
html: `
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
<a class="govuk-link" href="/${adjustment.person}/tagged-bail/edit/${adjustment.id}" data-qa="edit-${adjustment.id}">Edit</a><br />
</div>
<div class="govuk-grid-column-one-quarter">
<a class="govuk-link" href="/${adjustment.person}/tagged-bail/delete/${adjustment.id}" data-qa="delete-${adjustment.id}">Delete</a><br />
</div>
</div>
`,
}
}
}
1 change: 1 addition & 0 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default function routes(service: Services): Router {
get('/:nomsId/remand/no-applicable-sentences', remandRoutes.noApplicableSentences)

get('/:nomsId/tagged-bail/add', taggedBailRoutes.add)
get('/:nomsId/tagged-bail/view', taggedBailRoutes.view)
get('/:nomsId/tagged-bail/select-case/:addOrEdit/:id', taggedBailRoutes.selectCase)
get('/:nomsId/tagged-bail/days/:addOrEdit/:id', taggedBailRoutes.days)
post('/:nomsId/tagged-bail/days/:addOrEdit/:id', taggedBailRoutes.submitDays)
Expand Down
16 changes: 16 additions & 0 deletions server/routes/taggedBailRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,25 @@ describe('Tagged bail routes tests', () => {
})
})

it('GET /{nomsId}/tagged-bail/view shows correct information', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.findByPerson.mockResolvedValue([populatedAdjustment])
adjustmentsStoreService.getById.mockReturnValue(populatedAdjustment)
return request(app)
.get(`/${NOMS_ID}/tagged-bail/view`)
.expect(200)
.expect(res => {
expect(res.text).toContain('Tagged bail overview')
expect(res.text).toContain('Court 1')
expect(res.text).toContain('CASE001')
})
})

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)
return request(app)
.get(`/${NOMS_ID}/tagged-bail/review/add/${SESSION_ID}`)
Expand Down
27 changes: 27 additions & 0 deletions server/routes/taggedBailRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import TaggedBailDaysModel from '../model/taggedBailDaysModel'
import TaggedBailDaysForm from '../model/taggedBailDaysForm'
import TaggedBailReviewModel from '../model/taggedBailReviewModel'
import { Message } from '../model/adjustmentsHubViewModel'
import adjustmentTypes from '../model/adjustmentTypes'
import TaggedBailViewModel from '../model/taggedBailViewModel'

export default class TaggedBailRoutes {
constructor(
Expand Down Expand Up @@ -79,6 +81,31 @@ export default class TaggedBailRoutes {
return res.redirect(`/${nomsId}/tagged-bail/review/${addOrEdit}/${id}`)
}

public view: RequestHandler = async (req, res): Promise<void> => {
const { caseloads, token } = res.locals.user
const { nomsId } = req.params
const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token)
const adjustments = await this.adjustmentsService.findByPerson(nomsId, token)
const taggedBailAdjustments = adjustments.filter(it => it.adjustmentType === 'TAGGED_BAIL')
if (!taggedBailAdjustments) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!taggedBailAdjustments.length

If there are no tagged bail adjustments the filter will return an empty array which is truthy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've corrected this in the way you have suggested 👍

return res.redirect(`/${nomsId}`)
}

const adjustmentType = adjustmentTypes.find(it => it.url === 'tagged-bail')
if (!adjustmentType) {
return res.redirect(`/${nomsId}`)
}

const sentencesAndOffences = await this.prisonerService.getSentencesAndOffencesFilteredForRemand(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use getSentencesAndOffences over getSentencesAndOffencesFilteredForRemand.

The function you use filters out sentences that aren't applicable for remand (unrelated to tagged bail.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this method call in the way you have suggested 👍

prisonerDetail.bookingId,
token,
)

return res.render('pages/adjustments/tagged-bail/view', {
model: new TaggedBailViewModel(prisonerDetail, taggedBailAdjustments, adjustmentType, sentencesAndOffences),
})
}

public review: RequestHandler = async (req, res): Promise<void> => {
const { caseloads, token } = res.locals.user
const { nomsId, addOrEdit, id } = req.params
Expand Down
49 changes: 49 additions & 0 deletions server/views/pages/adjustments/tagged-bail/view.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends "../../../partials/layout.njk" %}
{% from "govuk/components/table/macro.njk" import govukTable %}
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}

{% set pageTitle = applicationName + " - view " + model.adjustmentType.shortText %}
{% set mainClasses = "app-container govuk-body" %}

{% block beforeContent %}
{{ super() }}
<nav>
{{ govukBackLink({
text: "Back",
href: "/" + model.prisonerDetail.offenderNo
}) }}
</nav>
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<span class="govuk-caption-xl">Adjust release dates</span>
Tagged bail overview
</h1>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-m">
Tagged Bail details
</h1>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukTable(
model.table()
) }}
<div>
{{ govukButton({
text: "Add new",
href: "/" + model.prisonerDetail.offenderNo + "/tagged-bail/add"
}) }}
</div>
<a href="/{{ model.prisonerDetail.offenderNo }}" class="govuk-link">Return to dashboard</a>
</div>
</div>
{% endblock %}
25 changes: 0 additions & 25 deletions server/views/partials/breadCrumb.njk

This file was deleted.