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

DT-2903 Added offender managers #17

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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