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

feat(j-s): New Subpoena #16168

Merged
merged 25 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ff2e71f
Locks subpoena fields when arraignment date has been set
gudjong Sep 25, 2024
cf631db
Move arraignment date message handling to the server side
gudjong Sep 25, 2024
9192246
Updates tests and fixes date comparison
gudjong Sep 25, 2024
2eb5958
Merge branch 'main' of github.com:island-is/island.is into j-s/indict…
gudjong Sep 25, 2024
f3a4c67
Merge branch 'main' of github.com:island-is/island.is into j-s/indict…
gudjong Sep 26, 2024
8124dbf
Schedules new subpoenas
gudjong Sep 26, 2024
5f3824a
Enforces operation ordering
gudjong Sep 26, 2024
33fe470
Only sends query parameters with new subpoena requests
gudjong Sep 26, 2024
4c86a72
Merge branch 'main' of github.com:island-is/island.is into j-s/indict…
gudjong Sep 27, 2024
414ec71
Supports multiple subpoenas per defendant
gudjong Sep 27, 2024
778daa1
Updates unit tests
gudjong Sep 27, 2024
8331d61
Updates unit test
gudjong Sep 27, 2024
9d0bb0f
Merge branch 'main' of github.com:island-is/island.is into j-s/indict…
gudjong Sep 27, 2024
185d7dd
Fixes some typs and null reference guards
gudjong Sep 30, 2024
331ea57
Improved type declaration
gudjong Sep 30, 2024
798c7f0
Improved date formatting
gudjong Sep 30, 2024
0fd6b37
Improves indexing
gudjong Sep 30, 2024
478a009
Fixes spelling
gudjong Sep 30, 2024
22d975f
Fixes indexing
gudjong Sep 30, 2024
cdaffc0
Fixes optional arguments
gudjong Sep 30, 2024
279f2f4
Removes redundant constructor
gudjong Sep 30, 2024
20bf0f1
Merge branch 'main' into j-s/indictment-case-new-subpoena
kodiakhq[bot] Sep 30, 2024
49b739c
Fix tests
oddsson Sep 30, 2024
532d3d6
Merge branch 'main' into j-s/indictment-case-new-subpoena
kodiakhq[bot] Sep 30, 2024
87db72b
Merge branch 'main' into j-s/indictment-case-new-subpoena
kodiakhq[bot] Sep 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
SubpoenaType,
} from '@island.is/judicial-system/types'

import { Subpoena } from './subpoena.model'

registerEnumType(Gender, { name: 'Gender' })
registerEnumType(DefendantPlea, { name: 'DefendantPlea' })
registerEnumType(ServiceRequirement, { name: 'ServiceRequirement' })
Expand Down Expand Up @@ -75,4 +77,7 @@ export class Defendant {

@Field(() => SubpoenaType, { nullable: true })
readonly subpoenaType?: SubpoenaType

@Field(() => [Subpoena], { nullable: true })
readonly subpoenas?: Subpoena[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Field, ID, ObjectType } from '@nestjs/graphql'

@ObjectType()
export class Subpoena {
@Field(() => ID)
readonly id!: string

@Field(() => String, { nullable: true })
created?: string

@Field(() => String, { nullable: true })
modified?: string
gudjong marked this conversation as resolved.
Show resolved Hide resolved

@Field(() => String, { nullable: true })
gudjong marked this conversation as resolved.
Show resolved Hide resolved
subpoenaId?: string

@Field(() => Boolean, { nullable: true })
acknowledged?: boolean

@Field(() => String, { nullable: true })
registeredBy?: string

@Field(() => String, { nullable: true })
comment?: string

@Field(() => String, { nullable: true })
arraignmentDate?: string

@Field(() => String, { nullable: true })
location?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,33 @@ export class FileController {
)
}

@Get('subpoena/:defendantId')
@Get(['subpoena/:defendantId', 'subpoena/:defendantId/:subpoenaId'])
@Header('Content-Type', 'application/pdf')
getSubpoenaPdf(
@Param('id') id: string,
@Param('defendantId') defendantId: string,
@Query('arraignmentDate') arraignmentDate: string,
@Query('location') location: string,
@Query('subpoenaType') subpoenaType: SubpoenaType,
@Param('subpoenaId') subpoenaId: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
@Query('arraignmentDate') arraignmentDate?: string,
@Query('location') location?: string,
@Query('subpoenaType') subpoenaType?: SubpoenaType,
): Promise<Response> {
this.logger.debug(
`Getting the subpoena for defendant ${defendantId} of case ${id} as a pdf document`,
)

const subpoenaIdInjection = subpoenaId ? `/${subpoenaId}` : ''
const queryInjection = arraignmentDate
? `?arraignmentDate=${arraignmentDate}&location=${location}&subpoenaType=${subpoenaType}`
: ''

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_SUBPOENA_PDF,
id,
`defendant/${defendantId}/subpoena?arraignmentDate=${arraignmentDate}&location=${location}&subpoenaType=${subpoenaType}`,
`defendant/${defendantId}/subpoena${subpoenaIdInjection}${queryInjection}`,
req,
res,
'pdf',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict'

module.exports = {
up(queryInterface, Sequelize) {
return queryInterface.sequelize.transaction((transaction) =>
Promise.all([
queryInterface.addColumn(
'subpoena',
'arraignment_date',
{
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
{ transaction },
),
queryInterface.addColumn(
'subpoena',
'location',
{ type: Sequelize.STRING, allowNull: false, defaultValue: 'óþekkt' },
{ transaction },
),
queryInterface.changeColumn(
'subpoena',
'case_id',
{
type: Sequelize.UUID,
allowNull: false,
},
{ transaction },
),
]).then(() =>
queryInterface.sequelize.query(
`ALTER TABLE subpoena ALTER COLUMN arraignment_date DROP DEFAULT;
ALTER TABLE subpoena ALTER COLUMN location DROP DEFAULT;`,
{ transaction },
),
),
)
},

down(queryInterface, Sequelize) {
return queryInterface.sequelize.transaction((transaction) =>
Promise.all([
queryInterface.removeColumn('subpoena', 'arraignment_date', {
transaction,
}),
queryInterface.removeColumn('subpoena', 'location', { transaction }),
queryInterface.changeColumn(
'subpoena',
'case_id',
{
type: Sequelize.UUID,
allowNull: true,
},
{ transaction },
),
]),
)
},
}
20 changes: 10 additions & 10 deletions apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
formatDOB,
lowercase,
} from '@island.is/judicial-system/formatters'
import { DateType, SubpoenaType } from '@island.is/judicial-system/types'
import { SubpoenaType } from '@island.is/judicial-system/types'

import { nowFactory } from '../factories/date.factory'
import { subpoena as strings } from '../messages'
import { Case } from '../modules/case'
import { Defendant } from '../modules/defendant'
import { Subpoena } from '../modules/subpoena'
import {
addConfirmation,
addEmptyLines,
Expand All @@ -27,6 +29,7 @@ export const createSubpoena = (
theCase: Case,
defendant: Defendant,
formatMessage: FormatMessage,
subpoena?: Subpoena,
arraignmentDate?: Date,
location?: string,
subpoenaType?: SubpoenaType,
Expand All @@ -43,28 +46,25 @@ export const createSubpoena = (
})

const sinc: Buffer[] = []
const dateLog = theCase.dateLogs?.find(
(d) => d.dateType === DateType.ARRAIGNMENT_DATE,
)

doc.on('data', (chunk) => sinc.push(chunk))

setTitle(doc, formatMessage(strings.title))

if (dateLog) {
if (subpoena) {
addEmptyLines(doc, 5)
}

addNormalText(doc, `${theCase.court?.name}`, 'Times-Bold', true)

addNormalRightAlignedText(
doc,
`${formatDate(new Date(dateLog?.modified ?? new Date()), 'PPP')}`,
`${formatDate(new Date(subpoena?.created ?? nowFactory()), 'PPP')}`,
'Times-Roman',
)

arraignmentDate = arraignmentDate ?? dateLog?.date
location = location ?? dateLog?.location
arraignmentDate = arraignmentDate ?? subpoena?.arraignmentDate
location = location ?? subpoena?.location
subpoenaType = subpoenaType ?? defendant.subpoenaType

if (theCase.court?.name) {
Expand Down Expand Up @@ -154,12 +154,12 @@ export const createSubpoena = (

addFooter(doc)

if (dateLog) {
if (subpoena) {
addConfirmation(doc, {
actor: theCase.judge?.name || '',
title: theCase.judge?.title,
institution: theCase.judge?.institution?.name || '',
date: dateLog.created,
date: subpoena.created,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
FileModule,
IndictmentCountModule,
PoliceModule,
SubpoenaModule,
UserModule,
} from '../index'
import { Case } from './models/case.model'
Expand All @@ -35,6 +36,7 @@ import { PdfService } from './pdf.service'
CmsTranslationsModule,
MessageModule,
forwardRef(() => DefendantModule),
forwardRef(() => SubpoenaModule),
gudjong marked this conversation as resolved.
Show resolved Hide resolved
forwardRef(() => UserModule),
forwardRef(() => FileModule),
forwardRef(() => IndictmentCountModule),
Expand Down
Loading
Loading