Skip to content

Commit

Permalink
DT-2903 Added offender managers (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
andymarke authored Dec 14, 2021
1 parent 6fea21e commit 747b5da
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/@types/express/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {}

export type RequestData = 'basicDetails' | 'sentences' | 'offences' | 'offendermanagers'
export type RequestData = 'basicDetails' | 'sentences' | 'offences' | 'offenderManagers'
export interface PrisonerSearchForm {
lastName?: string
prisonerNumber?: string
Expand Down
4 changes: 2 additions & 2 deletions server/routes/graphql/graphQLDemoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default class GraphqlDemoController {
const prisoners = await this.graphQLDemoService.search({}, req.session.prisonerSearchForm)

if (prisoners.length > 1) {
res.render('pages/graphql/search-results', { data: JSON.stringify(prisoners), prisoners })
res.render('pages/graphql/search-results', { prisoners })
} else if (prisoners.length === 1) {
res.render('pages/graphql/prisoner-details', { data: JSON.stringify(prisoners), prisoner: prisoners[0] })
res.render('pages/graphql/prisoner-details', { prisoner: prisoners[0] })
} else {
req.flash('errors', [{ text: 'No prisoners found' }])
res.redirect('/graphql/demo')
Expand Down
11 changes: 11 additions & 0 deletions server/services/graphQLDemoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export default class GraphQLDemoService {
}

function buildQueryDataRequest(request: PrisonerSearchForm): string {
const offenderManagers = request.data?.includes('offenderManagers')
? `offenderManagers {
firstName,
lastName,
responsibleOfficer,
type
}
`
: ''

const offences = request.data?.includes('offences')
? `offences {
id,
Expand Down Expand Up @@ -94,6 +104,7 @@ function buildQueryDataRequest(request: PrisonerSearchForm): string {
: ''
return `{
id,
${offenderManagers}
${offenderDetails}
${sentence}
}
Expand Down
45 changes: 44 additions & 1 deletion server/views/pages/graphql/prisoner-details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,43 @@
{% endif %}
{% endmacro %}

{% macro offenderManagers(offenderManagers) %}
{% if offenderManagers.length > 0 %}
{% set offenderManagerItems = [] %}

{% for offenderManager in offenderManagers %}
{% set offenderManagerItems = (offenderManagerItems.push(
[
{
text: offenderManager.lastName + ", " + offenderManager.firstName
},
{
text: "Prison Offender Manager" if offenderManager.type == "PRISON" else "Community Offender Manager"
},
{
text: "Yes" if offenderManager.responsibleOfficer else "No"
}
]
), offenderManagerItems) %}
{% endfor %}
{{ govukTable({
captionClasses: "govuk-table__caption--m",
head: [
{
text: "Name"
},
{
text: "Type"
},
{
text: "RO"
}
],
rows: offenderManagerItems
}) }}
{% endif %}
{% endmacro %}

{% block content %}

<main class="app-container govuk-body">
Expand All @@ -48,7 +85,7 @@
text: "First name"
},
value: {
text: prisoner.lastName
text: prisoner.firstName
},
actions: {
items: [
Expand Down Expand Up @@ -96,6 +133,12 @@
}
]
}) }}

{{
offenderManagers(prisoner.offenderManagers)
}}


{% if prisoner.sentences.length %}
<h2 class="govuk-heading-m govuk-!-margin-top-7">Sentences</h2>
{% set sentenceItems = [] %}
Expand Down

0 comments on commit 747b5da

Please sign in to comment.