-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 8 commits
8b349b1
692cdb7
5ada5af
9b94631
d2d44c8
23c9164
dd86500
5c93661
580f5ab
860976b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved some logic out of the |
||
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> | ||
`, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use The function you use filters out sentences that aren't applicable for remand (unrelated to tagged bail.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 %} |
This file was deleted.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍