Skip to content

Commit

Permalink
Merge branch 'main' into feat/use-smart-solutions-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
thorkellmani authored Oct 1, 2024
2 parents 60d7b16 + 9ef986b commit 89edd13
Show file tree
Hide file tree
Showing 226 changed files with 6,004 additions and 987 deletions.
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

@Field(() => String, { nullable: true })
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
}
16 changes: 11 additions & 5 deletions apps/judicial-system/api/src/app/modules/file/file.controller.ts
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),
forwardRef(() => UserModule),
forwardRef(() => FileModule),
forwardRef(() => IndictmentCountModule),
Expand Down
Loading

0 comments on commit 89edd13

Please sign in to comment.