Skip to content

Commit

Permalink
feat(j-s): Display service status (#16177)
Browse files Browse the repository at this point in the history
* Locks subpoena fields when arraignment date has been set

* Show subpoena status

* Move arraignment date message handling to the server side

* Updates tests and fixes date comparison

* Change subpoena data structure

* Checkpoint

* Map ServiceStatus to human readable text

* Defender and electronically service

* Schedules new subpoenas

* Enforces operation ordering

* Only sends query parameters with new subpoena requests

* Service to defender

* Sort in asc order

* Cleanup

* Checkpoint

* Supports multiple subpoenas per defendant

* Updates unit tests

* Updates unit test

* Fixes some typs and null reference guards

* Improved type declaration

* Improved date formatting

* Improves indexing

* Fixes spelling

* Fixes indexing

* Fixes optional arguments

* Removes redundant constructor

* Fix key error

* Remove unused import

* Remove unused import

* Fix tests

* Checkpoint

* Checkpoint

* Checkpoint

* Save subpoena status in DB

* Error handling

* Move error handling

* Update police.service.ts

* Merge

* Update police.service.ts

* Update police.service.ts

* Update police.service.ts

* Error handling in frontend

* Cleanup

* Cleanup

* Cleanup

* Revert processing

* Cleanup

* Error handling

* Add to prosecutor screen

* Remove double encoding code

* Hide ServiceAnnouncement if no subpoena id

* Use correct data

* Add defender national id

* Fix Slack log

* Rename interface

* fix(j-s): xrd fixes

* Update app.service.ts

* Update updateSubpoena.dto.ts

* fix(j-s): module import

* Revert "fix(j-s): module import"

This reverts commit a11885c.

* Update createTestingPoliceModule.ts

---------

Co-authored-by: Guðjón Guðjónsson <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: unakb <[email protected]>
  • Loading branch information
4 people authored Oct 7, 2024
1 parent f1b145f commit 8594e56
Show file tree
Hide file tree
Showing 33 changed files with 657 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { Institution } from '../institution'
import {
PoliceCaseFile,
PoliceCaseInfo,
SubpoenaStatus,
UploadPoliceCaseFileResponse,
} from '../police'
import { backendModuleConfig } from './backend.config'
Expand Down Expand Up @@ -306,6 +307,13 @@ export class BackendService extends DataSource<{ req: Request }> {
return this.get(`case/${caseId}/policeFiles`)
}

getSubpoenaStatus(
caseId: string,
subpoenaId: string,
): Promise<SubpoenaStatus> {
return this.get(`case/${caseId}/subpoenaStatus/${subpoenaId}`)
}

getPoliceCaseInfo(caseId: string): Promise<PoliceCaseInfo[]> {
return this.get(`case/${caseId}/policeCaseInfo`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { Defendant } from './models/defendant.model'
export { DeleteDefendantResponse } from './models/delete.response'
export { CivilClaimant } from './models/civilClaimant.model'
export { DeleteCivilClaimantResponse } from './models/deleteCivilClaimant.response'
export { Subpoena } from './models/subpoena.model'
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Field, ID, ObjectType } from '@nestjs/graphql'
import { Field, ID, ObjectType, registerEnumType } from '@nestjs/graphql'

import { ServiceStatus } from '@island.is/judicial-system/types'

registerEnumType(ServiceStatus, { name: 'ServiceStatus' })

@ObjectType()
export class Subpoena {
Expand All @@ -14,15 +18,27 @@ export class Subpoena {
@Field(() => String, { nullable: true })
subpoenaId?: string

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

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

@Field(() => ServiceStatus, { nullable: true })
serviceStatus?: ServiceStatus

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Allow } from 'class-validator'

import { Field, ID, InputType } from '@nestjs/graphql'

@InputType()
export class SubpoenaStatusQueryInput {
@Allow()
@Field(() => ID)
readonly caseId!: string

@Allow()
@Field(() => ID)
readonly subpoenaId!: string
}
1 change: 1 addition & 0 deletions apps/judicial-system/api/src/app/modules/police/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { PoliceCaseInfo } from './models/policeCaseInfo.model'
export { SubpoenaStatus } from './models/subpoenaStatus.model'
export { PoliceCaseFile } from './models/policeCaseFile.model'
export { UploadPoliceCaseFileResponse } from './models/uploadPoliceCaseFile.response'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Field, ObjectType } from '@nestjs/graphql'

import { ServiceStatus } from '@island.is/judicial-system/types'

@ObjectType()
export class SubpoenaStatus {
@Field(() => ServiceStatus)
readonly serviceStatus!: ServiceStatus

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

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

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

@Field(() => String, { nullable: true })
readonly defenderNationalId?: string
}
22 changes: 22 additions & 0 deletions apps/judicial-system/api/src/app/modules/police/police.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import type { User } from '@island.is/judicial-system/types'
import { BackendService } from '../backend'
import { PoliceCaseFilesQueryInput } from './dto/policeCaseFiles.input'
import { PoliceCaseInfoQueryInput } from './dto/policeCaseInfo.input'
import { SubpoenaStatusQueryInput } from './dto/subpoenaStatus.input'
import { UploadPoliceCaseFileInput } from './dto/uploadPoliceCaseFile.input'
import { PoliceCaseFile } from './models/policeCaseFile.model'
import { PoliceCaseInfo } from './models/policeCaseInfo.model'
import { SubpoenaStatus } from './models/subpoenaStatus.model'
import { UploadPoliceCaseFileResponse } from './models/uploadPoliceCaseFile.response'

@UseGuards(JwtGraphQlAuthGuard)
Expand Down Expand Up @@ -49,6 +51,26 @@ export class PoliceResolver {
)
}

@Query(() => SubpoenaStatus, { nullable: true })
subpoenaStatus(
@Args('input', { type: () => SubpoenaStatusQueryInput })
input: SubpoenaStatusQueryInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<SubpoenaStatus> {
this.logger.debug(
`Getting subpoena status for subpoena ${input.subpoenaId} of case ${input.caseId}`,
)

return this.auditTrailService.audit(
user.id,
AuditedAction.GET_SUBPOENA_STATUS,
backendService.getSubpoenaStatus(input.caseId, input.subpoenaId),
input.caseId,
)
}

@Query(() => [PoliceCaseInfo], { nullable: true })
policeCaseInfo(
@Args('input', { type: () => PoliceCaseInfoQueryInput })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict'

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((transaction) =>
queryInterface
.changeColumn(
'subpoena',
'acknowledged',
{ type: Sequelize.STRING, allowNull: true },
{ transaction },
)
.then(
() =>
queryInterface.renameColumn(
'subpoena',
'acknowledged',
'service_status',
{ transaction },
),

queryInterface.renameColumn(
'subpoena',
'acknowledged_date',
'service_date',
{ transaction },
),

queryInterface.renameColumn(
'subpoena',
'registered_by',
'served_by',
{ transaction },
),

queryInterface.addColumn(
'subpoena',
'defender_national_id',
{
type: Sequelize.STRING,
allowNull: true,
},
{ transaction },
),
),
)
},

down: (queryInterface) => {
return queryInterface.sequelize.transaction((transaction) =>
queryInterface
.renameColumn('subpoena', 'service_status', 'acknowledged', {
transaction,
})
.then(
() =>
queryInterface.changeColumn(
'subpoena',
'acknowledged',
{
type: 'BOOLEAN USING CAST("acknowledged" as BOOLEAN)',
allowNull: true,
},
{ transaction },
),

queryInterface.renameColumn(
'subpoena',
'service_date',
'acknowledged_date',
{ transaction },
),

queryInterface.renameColumn(
'subpoena',
'served_by',
'registered_by',
{ transaction },
),

queryInterface.removeColumn('subpoena', 'defender_national_id', {
transaction,
}),
),
)
},
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import CryptoJS from 'crypto-js'
import format from 'date-fns/format'
import { Base64 } from 'js-base64'
import { Op } from 'sequelize'
import { Sequelize } from 'sequelize-typescript'

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { CanActivate } from '@nestjs/common'

import { JwtAuthGuard, RolesGuard } from '@island.is/judicial-system/auth'
import { indictmentCases } from '@island.is/judicial-system/types'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from '@island.is/judicial-system/types'

import { type Case } from '../case'
import { CaseString } from '../case/models/caseString.model'
import { DateLog } from '../case/models/dateLog.model'
import { eventModuleConfig } from './event.config'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { CanActivate } from '@nestjs/common'

import { RolesGuard } from '@island.is/judicial-system/auth'

import { CaseExistsGuard, CaseReadGuard } from '../../../case'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
} from '@island.is/judicial-system/auth'
import type { User } from '@island.is/judicial-system/types'

import { prosecutorRepresentativeRule, prosecutorRule } from '../../guards'
import {
districtCourtJudgeRule,
prosecutorRepresentativeRule,
prosecutorRule,
} from '../../guards'
import {
Case,
CaseExistsGuard,
Expand All @@ -30,6 +34,7 @@ import {
CaseReadGuard,
CurrentCase,
} from '../case'
import { Subpoena } from '../subpoena'
import { UploadPoliceCaseFileDto } from './dto/uploadPoliceCaseFile.dto'
import { PoliceCaseFile } from './models/policeCaseFile.model'
import { PoliceCaseInfo } from './models/policeCaseInfo.model'
Expand Down Expand Up @@ -69,6 +74,26 @@ export class PoliceController {
return this.policeService.getAllPoliceCaseFiles(theCase.id, user)
}

@RolesRules(
prosecutorRule,
prosecutorRepresentativeRule,
districtCourtJudgeRule,
)
@Get('subpoenaStatus/:subpoenaId')
@ApiOkResponse({
type: Subpoena,
description: 'Gets subpoena status',
})
getSubpoenaStatus(
@Param('subpoenaId') subpoenaId: string,
@CurrentCase() theCase: Case,
@CurrentHttpUser() user: User,
): Promise<Subpoena> {
this.logger.debug(`Gets subpoena status in case ${theCase.id}`)

return this.policeService.getSubpoenaStatus(subpoenaId, user)
}

@RolesRules(prosecutorRule, prosecutorRepresentativeRule)
@UseInterceptors(CaseOriginalAncestorInterceptor)
@Get('policeCaseInfo')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forwardRef, Module } from '@nestjs/common'

import { AwsS3Module, CaseModule, EventModule } from '../index'
import { AwsS3Module, CaseModule, EventModule, SubpoenaModule } from '../index'
import { PoliceController } from './police.controller'
import { PoliceService } from './police.service'

Expand All @@ -9,6 +9,7 @@ import { PoliceService } from './police.service'
forwardRef(() => CaseModule),
forwardRef(() => EventModule),
forwardRef(() => AwsS3Module),
forwardRef(() => SubpoenaModule),
],
providers: [PoliceService],
exports: [PoliceService],
Expand Down
Loading

0 comments on commit 8594e56

Please sign in to comment.