Skip to content

Commit

Permalink
Merge branch 'main' into fix/ff-income-plan
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 16, 2024
2 parents 5af6f00 + 554599b commit 14e9dca
Show file tree
Hide file tree
Showing 206 changed files with 4,338 additions and 2,159 deletions.
780 changes: 394 additions & 386 deletions .github/CODEOWNERS

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions apps/judicial-system/backend/src/app/messages/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,4 +856,19 @@ export const notifications = {
description: 'Texti í pósti til aðila máls þegar ný gögn eru send',
},
}),
courtOfficialAssignedEmail: defineMessages({
subject: {
id: 'judicial.system.backend:notifications.court_official_assigned_email.subject',
defaultMessage: 'Úthlutun máls {courtCaseNumber}',
description:
'Fyrirsögn í pósti til dómara og dómritara þegar máli er úthlutað á þau',
},
body: {
id: 'judicial.system.backend:notifications.court_official_assigned_email.body',
defaultMessage:
'Héraðsdómur hefur skráð þig sem {role, select, DISTRICT_COURT_JUDGE {dómara} DISTRICT_COURT_REGISTRAR {dómritara} other {óþekkt}} í máli {courtCaseNumber}. Hægt er að nálgast gögn málsins á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}',
description:
'Texti í pósti til dómara og dómritara þegar máli er úthlutað á þau',
},
}),
}
73 changes: 73 additions & 0 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
eventTypes,
isCompletedCase,
isIndictmentCase,
isInvestigationCase,
isRequestCase,
isTrafficViolationCase,
notificationTypes,
Expand Down Expand Up @@ -686,6 +687,34 @@ export class CaseService {
])
}

private addMessagesForDistrictCourtJudgeAssignedToQueue(
theCase: Case,
user: TUser,
): Promise<void> {
return this.messageService.sendMessagesToQueue([
{
type: MessageType.NOTIFICATION,
user,
caseId: theCase.id,
body: { type: CaseNotificationType.DISTRICT_COURT_JUDGE_ASSIGNED },
},
])
}

private addMessagesForDistrictCourtRegistrarAssignedToQueue(
theCase: Case,
user: TUser,
): Promise<void> {
return this.messageService.sendMessagesToQueue([
{
type: MessageType.NOTIFICATION,
user,
caseId: theCase.id,
body: { type: CaseNotificationType.DISTRICT_COURT_REGISTRAR_ASSIGNED },
},
])
}

private addMessagesForReceivedCaseToQueue(
theCase: Case,
user: TUser,
Expand Down Expand Up @@ -845,7 +874,25 @@ export class CaseService {
this.getDeliverProsecutorToCourtMessages(theCase, user),
)
}
private addMessagesForSignedCourtRecordToQueue(
theCase: Case,
user: TUser,
): Promise<void> {
const messages = []

if (
theCase.origin === CaseOrigin.LOKE &&
isInvestigationCase(theCase.type)
) {
messages.push({
type: MessageType.DELIVERY_TO_POLICE_SIGNED_COURT_RECORD,
user,
caseId: theCase.id,
})
}

return this.messageService.sendMessagesToQueue(messages)
}
private addMessagesForSignedRulingToQueue(
theCase: Case,
user: TUser,
Expand Down Expand Up @@ -1384,6 +1431,30 @@ export class CaseService {
}
}

if (
isIndictment &&
[CaseState.SUBMITTED, CaseState.RECEIVED].includes(updatedCase.state)
) {
const isJudgeChanged =
updatedCase.judge?.nationalId !== theCase.judge?.nationalId
const isRegistrarChanged =
updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId

if (isJudgeChanged) {
await this.addMessagesForDistrictCourtJudgeAssignedToQueue(
updatedCase,
user,
)
}

if (isRegistrarChanged) {
await this.addMessagesForDistrictCourtRegistrarAssignedToQueue(
updatedCase,
user,
)
}
}

if (
isIndictment &&
![
Expand Down Expand Up @@ -1899,6 +1970,8 @@ export class CaseService {
false,
)

await this.addMessagesForSignedCourtRecordToQueue(theCase, user)

return { documentSigned: true }
} catch (error) {
this.eventService.postErrorEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,35 @@ export class InternalCaseController {
)
}

@UseGuards(
CaseExistsGuard,
new CaseTypeGuard([...restrictionCases, ...investigationCases]),
CaseCompletedGuard,
)
@Post(
`case/:caseId/${
messageEndpoint[MessageType.DELIVERY_TO_POLICE_SIGNED_COURT_RECORD]
}`,
)
@ApiOkResponse({
type: DeliverResponse,
description: 'Delivers a signed court record to police',
})
deliverSignedCourtRecordToPolice(
@Param('caseId') caseId: string,
@CurrentCase() theCase: Case,
@Body() deliverDto: DeliverDto,
): Promise<DeliverResponse> {
this.logger.debug(
`Delivering the signed court record for case ${caseId} to police`,
)

return this.internalCaseService.deliverSignedCourtRecordToPolice(
theCase,
deliverDto.user,
)
}

@UseGuards(
CaseExistsGuard,
new CaseTypeGuard([...restrictionCases, ...investigationCases]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ export class InternalCaseService {
)
}

private getSignedCourtRecordPdf(theCase: Case) {
return this.awsS3Service.getGeneratedRequestCaseObject(
theCase.type,
`${theCase.id}/courtRecord.pdf`,
)
}

private async deliverSignedRulingPdfToCourt(
theCase: Case,
user: TUser,
Expand Down Expand Up @@ -606,6 +613,7 @@ export class InternalCaseService {
? {
name: theCase.prosecutor.name,
nationalId: theCase.prosecutor.nationalId,
email: theCase.prosecutor.email,
}
: undefined,
)
Expand Down Expand Up @@ -1099,6 +1107,32 @@ export class InternalCaseService {
return { delivered }
}

async deliverSignedCourtRecordToPolice(
theCase: Case,
user: TUser,
): Promise<DeliverResponse> {
const delivered = await this.getSignedCourtRecordPdf(theCase)
.then((pdf) =>
this.deliverCaseToPoliceWithFiles(theCase, user, [
{
type: PoliceDocumentType.RVTB,
courtDocument: Base64.btoa(pdf.toString('binary')),
},
]),
)
.catch((reason) => {
// Tolerate failure, but log error
this.logger.error(
`Failed to deliver signed court record for case ${theCase.id} to police`,
{ reason },
)

return false
})

return { delivered }
}

async deliverSignedRulingToPolice(
theCase: Case,
user: TUser,
Expand All @@ -1115,7 +1149,7 @@ export class InternalCaseService {
.catch((reason) => {
// Tolerate failure, but log error
this.logger.error(
`Failed to deliver sigend ruling for case ${theCase.id} to police`,
`Failed to deliver signed ruling for case ${theCase.id} to police`,
{ reason },
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ describe('InternalCaseController - Deliver indictment info to court', () => {
{ eventType: EventType.INDICTMENT_CONFIRMED, created: indictmentDate },
],
defendants: [{ name: 'Test Ákærði', nationalId: '1234567890' }],
prosecutor: { name: 'Test Sækjandi', nationalId: '0101010101' },
prosecutor: {
name: 'Test Sækjandi',
nationalId: '0101010101',
email: '[email protected]',
},
} as Case

let mockCourtService: CourtService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Base64 } from 'js-base64'
import { uuid } from 'uuidv4'

import {
CaseOrigin,
CaseState,
CaseType,
User,
} from '@island.is/judicial-system/types'

import { createTestingCaseModule } from '../createTestingCaseModule'

import { nowFactory } from '../../../../factories'
import { randomDate } from '../../../../test'
import { AwsS3Service } from '../../../aws-s3'
import { PoliceDocumentType, PoliceService } from '../../../police'
import { Case } from '../../models/case.model'
import { DeliverResponse } from '../../models/deliver.response'

jest.mock('../../../../factories')

interface Then {
result: DeliverResponse
error: Error
}

type GivenWhenThen = (caseId: string, theCase: Case) => Promise<Then>

describe('InternalCaseController - Deliver signed court record to police', () => {
const userId = uuid()
const user = { id: userId } as User

let mockAwsS3Service: AwsS3Service
let mockPoliceService: PoliceService
let givenWhenThen: GivenWhenThen

beforeEach(async () => {
const { awsS3Service, policeService, internalCaseController } =
await createTestingCaseModule()

mockAwsS3Service = awsS3Service
mockPoliceService = policeService

const mockGetGeneratedObject =
awsS3Service.getGeneratedRequestCaseObject as jest.Mock
mockGetGeneratedObject.mockRejectedValue(new Error('Some error'))
const mockUpdatePoliceCase = mockPoliceService.updatePoliceCase as jest.Mock
mockUpdatePoliceCase.mockRejectedValue(new Error('Some error'))

givenWhenThen = async (caseId: string, theCase: Case) => {
const then = {} as Then

await internalCaseController
.deliverSignedCourtRecordToPolice(caseId, theCase, { user })
.then((result) => (then.result = result))
.catch((error) => (then.error = error))

return then
}
})

describe('deliver case to police', () => {
const caseId = uuid()
const caseType = CaseType.PHONE_TAPPING
const caseState = CaseState.ACCEPTED
const policeCaseNumber = uuid()
const courtCaseNumber = uuid()
const defendantNationalId = '0123456789'
const validToDate = randomDate()
const caseConclusion = 'test conclusion'
const theCase = {
id: caseId,
origin: CaseOrigin.LOKE,
type: caseType,
state: caseState,
policeCaseNumbers: [policeCaseNumber],
courtCaseNumber,
defendants: [{ nationalId: defendantNationalId }],
validToDate,
conclusion: caseConclusion,
} as Case
const courtRecordPdf = 'test court record'

let then: Then

beforeEach(async () => {
const mockToday = nowFactory as jest.Mock
mockToday.mockReturnValueOnce(validToDate)

const mockGetGeneratedObject =
mockAwsS3Service.getGeneratedRequestCaseObject as jest.Mock
mockGetGeneratedObject.mockResolvedValueOnce(courtRecordPdf)
const mockUpdatePoliceCase =
mockPoliceService.updatePoliceCase as jest.Mock
mockUpdatePoliceCase.mockResolvedValueOnce(true)

then = await givenWhenThen(caseId, theCase)
})

it('should update the police case with a signed court record', async () => {
expect(
mockAwsS3Service.getGeneratedRequestCaseObject,
).toHaveBeenCalledWith(caseType, `${caseId}/courtRecord.pdf`)
expect(mockPoliceService.updatePoliceCase).toHaveBeenCalledWith(
user,
caseId,
caseType,
caseState,
policeCaseNumber,
courtCaseNumber,
defendantNationalId,
validToDate,
caseConclusion,
[
{
type: PoliceDocumentType.RVTB,
courtDocument: Base64.btoa(courtRecordPdf),
},
],
)
expect(then.result.delivered).toEqual(true)
})
})
})
Loading

0 comments on commit 14e9dca

Please sign in to comment.