Skip to content

Commit

Permalink
Merge branch 'main' into j-s/paste-cases-table-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Nov 27, 2024
2 parents 3ca5a67 + 14a7777 commit e462422
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 75 deletions.
37 changes: 30 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
node_modules/
dist/
scripts/ci/
# vi: ft=gitignore

# Known ignores
/.github/
/.git/
/scripts/ci/
/.env.*
/.envrc*

# Cache and packages
**/node_modules/
**/cache/
/cache*
cache/
.git/
log/
*.log

# Logs and temporaries
**/log/
**/*.log
**/tmp/
**/temp/

# Outputs
**/dist/
**/out/

# Docker-stuff
**/Dockerfile
**/Dockerfile.*
**/Containerfile
**/Containerfile.*
**/*-compose.yaml
**/*-compose.yml
2 changes: 2 additions & 0 deletions apps/judicial-system/backend/infra/judicial-system-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const serviceSetup = (): ServiceBuilder<'judicial-system-backend'> =>
EMAIL_REPLY_TO_NAME: '/k8s/judicial-system/EMAIL_REPLY_TO_NAME',
PRISON_EMAIL: '/k8s/judicial-system/PRISON_EMAIL',
PRISON_ADMIN_EMAIL: '/k8s/judicial-system/PRISON_ADMIN_EMAIL',
PRISON_ADMIN_INDICTMENT_EMAILS:
'/k8s/judicial-system/PRISON_ADMIN_INDICTMENT_EMAILS',
AUTH_JWT_SECRET: '/k8s/judicial-system/AUTH_JWT_SECRET',
ADMIN_USERS: '/k8s/judicial-system/ADMIN_USERS',
BACKEND_ACCESS_TOKEN: '/k8s/judicial-system/BACKEND_ACCESS_TOKEN',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ export class DefendantService {
return message
}

private getMessagesForIndictmentToPrisonAdminChanges(
defendant: Defendant,
): Message {
const messageType =
defendant.isSentToPrisonAdmin === true
? DefendantNotificationType.INDICTMENT_SENT_TO_PRISON_ADMIN
: DefendantNotificationType.INDICTMENT_WITHDRAWN_FROM_PRISON_ADMIN

const message = {
type: MessageType.DEFENDANT_NOTIFICATION,
caseId: defendant.caseId,
elementId: defendant.id,
body: {
type: messageType,
},
}

return message
}

private getUpdatedDefendant(
numberOfAffectedRows: number,
defendants: Defendant[],
Expand Down Expand Up @@ -143,19 +163,19 @@ export class DefendantService {
return
}

const messages: Message[] = []

if (
updatedDefendant.isDefenderChoiceConfirmed &&
!oldDefendant.isDefenderChoiceConfirmed
) {
// Defender choice was just confirmed by the court
const messages: Message[] = [
{
type: MessageType.DELIVERY_TO_COURT_INDICTMENT_DEFENDER,
user,
caseId: theCase.id,
elementId: updatedDefendant.id,
},
]
messages.push({
type: MessageType.DELIVERY_TO_COURT_INDICTMENT_DEFENDER,
user,
caseId: theCase.id,
elementId: updatedDefendant.id,
})

if (
updatedDefendant.defenderChoice === DefenderChoice.CHOOSE ||
Expand All @@ -171,9 +191,20 @@ export class DefendantService {
})
}
}
} else if (
updatedDefendant.isSentToPrisonAdmin !== undefined &&
updatedDefendant.isSentToPrisonAdmin !== oldDefendant.isSentToPrisonAdmin
) {
messages.push(
this.getMessagesForIndictmentToPrisonAdminChanges(updatedDefendant),
)
}

return this.messageService.sendMessagesToQueue(messages)
if (messages.length === 0) {
return
}

return this.messageService.sendMessagesToQueue(messages)
}

async createForNewCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,58 @@ describe('DefendantController - Update', () => {
},
)

describe('defendant in indictment is sent to prison admin', () => {
const defendantUpdate = { isSentToPrisonAdmin: true }
const updatedDefendant = { ...defendant, ...defendantUpdate }

beforeEach(async () => {
const mockUpdate = mockDefendantModel.update as jest.Mock
mockUpdate.mockResolvedValueOnce([1, [updatedDefendant]])

await givenWhenThen(defendantUpdate, CaseType.INDICTMENT, caseId)
})

it('should queue messages', () => {
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([
{
type: MessageType.DEFENDANT_NOTIFICATION,
caseId,
elementId: defendantId,
body: {
type: DefendantNotificationType.INDICTMENT_SENT_TO_PRISON_ADMIN,
},
},
])
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledTimes(1)
})
})

describe('defendant in indictment is withdrawn from prison admin', () => {
const defendantUpdate = { isSentToPrisonAdmin: false }
const updatedDefendant = { ...defendant, ...defendantUpdate }

beforeEach(async () => {
const mockUpdate = mockDefendantModel.update as jest.Mock
mockUpdate.mockResolvedValueOnce([1, [updatedDefendant]])

await givenWhenThen(defendantUpdate, CaseType.INDICTMENT, caseId)
})

it('should queue messages for indictment withdrawn from prison admin', () => {
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([
{
type: MessageType.DEFENDANT_NOTIFICATION,
caseId,
elementId: defendantId,
body: {
type: DefendantNotificationType.INDICTMENT_WITHDRAWN_FROM_PRISON_ADMIN,
},
},
])
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledTimes(1)
})
})

describe('defendant update fails', () => {
let then: Then

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import { InstitutionNotificationDto } from './dto/institutionNotification.dto'
import { NotificationDispatchDto } from './dto/notificationDispatch.dto'
import { SubpoenaNotificationDto } from './dto/subpoenaNotification.dto'
import { DeliverResponse } from './models/deliver.response'
import { CaseNotificationService } from './caseNotification.service'
import { CivilClaimantNotificationService } from './civilClaimantNotification.service'
import { DefendantNotificationService } from './defendantNotification.service'
import { InstitutionNotificationService } from './institutionNotification.service'
import { CaseNotificationService } from './services/caseNotification/caseNotification.service'
import { CivilClaimantNotificationService } from './services/civilClaimantNotification/civilClaimantNotification.service'
import { DefendantNotificationService } from './services/defendantNotification/defendantNotification.service'
import { InstitutionNotificationService } from './services/institutionNotification/institutionNotification.service'
import { SubpoenaNotificationService } from './services/subpoenaNotification/subpoenaNotification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@UseGuards(TokenGuard)
@Controller('api/internal')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const notificationModuleConfig = defineConfig({
replyToName: env.required('EMAIL_REPLY_TO_NAME', 'Réttarvörslugátt'),
prisonEmail: env.required('PRISON_EMAIL', ''),
prisonAdminEmail: env.required('PRISON_ADMIN_EMAIL', ''),
prisonAdminIndictmentEmails: env.required(
'PRISON_ADMIN_INDICTMENT_EMAILS',
'',
),
courtsEmails: env.requiredJSON('COURTS_EMAILS', {}) as {
[key: string]: string
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
UserModule,
} from '../index'
import { Notification } from './models/notification.model'
import { CaseNotificationService } from './caseNotification.service'
import { CivilClaimantNotificationService } from './civilClaimantNotification.service'
import { DefendantNotificationService } from './defendantNotification.service'
import { InstitutionNotificationService } from './institutionNotification.service'
import { CaseNotificationService } from './services/caseNotification/caseNotification.service'
import { CivilClaimantNotificationService } from './services/civilClaimantNotification/civilClaimantNotification.service'
import { DefendantNotificationService } from './services/defendantNotification/defendantNotification.service'
import { InstitutionNotificationService } from './services/institutionNotification/institutionNotification.service'
import { SubpoenaNotificationService } from './services/subpoenaNotification/subpoenaNotification.service'
import { InternalNotificationController } from './internalNotification.controller'
import { NotificationController } from './notification.controller'
import { NotificationService } from './notification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@Module({
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ import {
formatProsecutorCourtDateEmailNotification,
formatProsecutorReadyForCourtEmailNotification,
formatProsecutorReceivedByCourtSmsNotification,
} from '../../formatters'
import { notifications } from '../../messages'
import { type Case, DateLog } from '../case'
import { CourtService } from '../court'
} from '../../../../formatters'
import { notifications } from '../../../../messages'
import { type Case, DateLog } from '../../../case'
import { CourtService } from '../../../court'
import {
type CivilClaimant,
type Defendant,
DefendantService,
} from '../defendant'
import { EventService } from '../event'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
import { notificationModuleConfig } from './notification.config'
} from '../../../defendant'
import { EventService } from '../../../event'
import { BaseNotificationService } from '../../baseNotification.service'
import { DeliverResponse } from '../../models/deliver.response'
import { Notification, Recipient } from '../../models/notification.model'
import { notificationModuleConfig } from '../../notification.config'

interface Attachment {
filename: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { DEFENDER_INDICTMENT_ROUTE } from '@island.is/judicial-system/consts'
import { capitalize } from '@island.is/judicial-system/formatters'
import { CivilClaimantNotificationType } from '@island.is/judicial-system/types'

import { Case } from '../case'
import { CivilClaimant } from '../defendant'
import { EventService } from '../event'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
import { Case } from '../../../case'
import { CivilClaimant } from '../../../defendant'
import { EventService } from '../../../event'
import { BaseNotificationService } from '../../baseNotification.service'
import { DeliverResponse } from '../../models/deliver.response'
import { Notification, Recipient } from '../../models/notification.model'
import { notificationModuleConfig } from '../../notification.config'
import { strings } from './civilClaimantNotification.strings'
import { notificationModuleConfig } from './notification.config'

@Injectable()
export class CivilClaimantNotificationService extends BaseNotificationService {
Expand Down
Loading

0 comments on commit e462422

Please sign in to comment.