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

chore(j-s): Send notifications when subpoena changes #16329

Merged
merged 51 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
067d728
Checkpoint
oddsson Oct 8, 2024
414f562
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 8, 2024
287a3a1
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 10, 2024
924ad3c
Refactor
oddsson Oct 10, 2024
0682944
Checkpoint
oddsson Oct 10, 2024
09f681f
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 10, 2024
bdbef5a
Add messages to queue
oddsson Oct 11, 2024
9353c83
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 11, 2024
b0953dc
Checkpoint
oddsson Oct 11, 2024
7544204
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 11, 2024
44e734d
Construct the emails
oddsson Oct 14, 2024
2588cb5
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 14, 2024
07f4561
Fix build
oddsson Oct 14, 2024
8479561
Checkpoint
oddsson Oct 14, 2024
9e42a37
Implement failed notifications
oddsson Oct 14, 2024
f56c6f1
Add failed and defenderchoice emails
oddsson Oct 14, 2024
82f925f
Remove unused code
oddsson Oct 14, 2024
3745b64
Remove unused code
oddsson Oct 14, 2024
ac82411
Refactor
oddsson Oct 14, 2024
1cb10f2
Refactor
oddsson Oct 14, 2024
bd9fca7
Remove unused code
oddsson Oct 14, 2024
83129b6
Refactor
oddsson Oct 14, 2024
4f5ca7a
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 14, 2024
548a152
Refactor
oddsson Oct 15, 2024
05da915
Refactor
oddsson Oct 15, 2024
f54358c
Refactor
oddsson Oct 15, 2024
b64168a
Refactor
oddsson Oct 15, 2024
a06a9cd
Refactor
oddsson Oct 15, 2024
11cb44e
Refactor
oddsson Oct 15, 2024
6a715e9
Refactor
oddsson Oct 15, 2024
5e1de12
Refactor
oddsson Oct 15, 2024
48d0c4d
Refactor
oddsson Oct 15, 2024
f7382b5
Refactor
oddsson Oct 15, 2024
deb2092
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 15, 2024
01ca587
Refactor
oddsson Oct 15, 2024
2c4d6e2
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 16, 2024
bb1561b
Merge branch 'j-s/notifications-defendant-selected-defender' of githu…
oddsson Oct 16, 2024
40f6e8f
Merge
oddsson Oct 16, 2024
e91e402
Cleanup
oddsson Oct 16, 2024
7cf8113
Remove console.log
oddsson Oct 16, 2024
4322579
Refactor
oddsson Oct 16, 2024
91959e9
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 17, 2024
65203c4
Refactor
oddsson Oct 17, 2024
c411118
Refactor
oddsson Oct 17, 2024
5bfeb79
Remove unused code
oddsson Oct 17, 2024
dfa4abe
Refactor
oddsson Oct 17, 2024
e980af2
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 18, 2024
bd5b1b2
Fix tests
oddsson Oct 18, 2024
44a7c57
Merge branch 'main' of github.com:island-is/island.is into j-s/notifi…
oddsson Oct 18, 2024
c26d006
Merge branch 'main' into j-s/notifications-defendant-selected-defender
kodiakhq[bot] Oct 18, 2024
1c7be80
Merge branch 'main' into j-s/notifications-defendant-selected-defender
kodiakhq[bot] Oct 18, 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
@@ -0,0 +1,70 @@
'use strict'
const replaceEnum = require('sequelize-replace-enum-postgres').default

module.exports = {
up: (queryInterface) => {
// replaceEnum does not support transactions
return replaceEnum({
queryInterface,
tableName: 'notification',
columnName: 'type',
newValues: [
'HEADS_UP',
'READY_FOR_COURT',
'RECEIVED_BY_COURT',
'COURT_DATE',
'RULING',
'MODIFIED',
'REVOKED',
'DEFENDER_ASSIGNED',
'ADVOCATE_ASSIGNED',
'DEFENDANTS_NOT_UPDATED_AT_COURT',
'APPEAL_TO_COURT_OF_APPEALS',
'APPEAL_RECEIVED_BY_COURT',
'APPEAL_STATEMENT',
'APPEAL_COMPLETED',
'APPEAL_JUDGES_ASSIGNED',
'APPEAL_CASE_FILES_UPDATED',
'APPEAL_WITHDRAWN',
'INDICTMENT_DENIED',
'INDICTMENT_RETURNED',
'INDICTMENTS_WAITING_FOR_CONFIRMATION',
'SERVICE_SUCCESSFUL', // New value
'SERVICE_FAILED', // New value
'DEFENDANT_SELECTED_DEFENDER', // New value
],
enumName: 'enum_notification_type',
})
},

down: (queryInterface) => {
// replaceEnum does not support transactions
return replaceEnum({
queryInterface,
tableName: 'notification',
columnName: 'type',
newValues: [
'HEADS_UP',
'READY_FOR_COURT',
'RECEIVED_BY_COURT',
'COURT_DATE',
'RULING',
'MODIFIED',
'REVOKED',
'DEFENDER_ASSIGNED',
'DEFENDANTS_NOT_UPDATED_AT_COURT',
'APPEAL_TO_COURT_OF_APPEALS',
'APPEAL_RECEIVED_BY_COURT',
'APPEAL_STATEMENT',
'APPEAL_COMPLETED',
'APPEAL_JUDGES_ASSIGNED',
'APPEAL_CASE_FILES_UPDATED',
'APPEAL_WITHDRAWN',
'INDICTMENT_DENIED',
'INDICTMENT_RETURNED',
'INDICTMENTS_WAITING_FOR_CONFIRMATION',
],
enumName: 'enum_notification_type',
})
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,28 @@ export abstract class BaseNotificationService {
),
}
}

protected hasSentNotification(
type: NotificationType,
notifications?: Notification[],
) {
return notifications?.some((notification) => notification.type === type)
}

protected hasReceivedNotification(
type?: NotificationType | NotificationType[],
address?: string,
notifications?: Notification[],
) {
const types = type ? [type].flat() : Object.values(NotificationType)

return notifications?.some((notification) => {
return (
types.includes(notification.type) &&
notification.recipients.some(
(recipient) => recipient.address === address && recipient.success,
)
)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IsEnum, IsNotEmpty } from 'class-validator'

import { ApiProperty } from '@nestjs/swagger'

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

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

export class SubpoenaNotificationDto {
@IsNotEmpty()
@IsEnum(NotificationType)
@ApiProperty({ enum: NotificationType })
readonly type!: NotificationType

@IsNotEmpty()
@ApiProperty({ type: Subpoena })
readonly subpoena!: Subpoena
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ export class InstitutionNotificationService extends BaseNotificationService {
}

private async sendIndictmentsWaitingForConfirmationNotification(
prosecutorsOfficeId: string,
prosecutorsOfficeId?: string,
): Promise<unknown> {
if (!prosecutorsOfficeId) {
oddsson marked this conversation as resolved.
Show resolved Hide resolved
return
}

const count =
await this.internalCaseService.countIndictmentsWaitingForConfirmation(
prosecutorsOfficeId,
Expand Down Expand Up @@ -87,7 +91,7 @@ export class InstitutionNotificationService extends BaseNotificationService {

async sendNotification(
type: NotificationType,
prosecutorsOfficeId: string,
prosecutorsOfficeId?: string,
): Promise<DeliverResponse> {
try {
switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import {
import { Case, CaseHasExistedGuard, CurrentCase } from '../case'
import { CaseNotificationDto } from './dto/caseNotification.dto'
import { InstitutionNotificationDto } from './dto/institutionNotification.dto'
import { NotificationDto } from './dto/notification.dto'
import { SubpoenaNotificationDto } from './dto/subpoenaNotification.dto'
import { DeliverResponse } from './models/deliver.response'
import { InstitutionNotificationService } from './institutionNotification.service'
import { InternalNotificationService } from './internalNotification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@UseGuards(TokenGuard)
@Controller('api/internal')
Expand All @@ -34,6 +35,7 @@ export class InternalNotificationController {
private readonly internalNotificationService: InternalNotificationService,
private readonly notificationDispatchService: NotificationDispatchService,
private readonly institutionNotificationService: InstitutionNotificationService,
private readonly subpoenaNotificationService: SubpoenaNotificationService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

Expand Down Expand Up @@ -75,13 +77,29 @@ export class InternalNotificationController {
)
}

@Post(messageEndpoint[MessageType.SUBPOENA_NOTIFICATION])
@ApiCreatedResponse({
type: DeliverResponse,
description: 'Sends a new notification',
})
sendSubpoenaNotification(
@Body() notificationDto: SubpoenaNotificationDto,
): Promise<DeliverResponse> {
this.logger.debug(`Sending ${notificationDto.type} notification`)

return this.subpoenaNotificationService.sendNotification(
notificationDto.type,
notificationDto.subpoena,
)
}

@Post(messageEndpoint[MessageType.NOTIFICATION_DISPATCH])
@ApiCreatedResponse({
type: DeliverResponse,
description: 'Dispatches notifications',
})
dispatchNotification(
@Body() notificationDto: NotificationDto,
@Body() notificationDto: InstitutionNotificationDto,
): Promise<DeliverResponse> {
this.logger.debug(`Dispatching ${notificationDto.type} notification`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,6 @@ export class InternalNotificationService extends BaseNotificationService {
)
}

private hasSentNotification(
type: NotificationType,
notifications?: Notification[],
) {
return notifications?.some((notification) => notification.type === type)
}

private hasReceivedNotification(
type?: NotificationType | NotificationType[],
address?: string,
notifications?: Notification[],
) {
const types = type ? [type].flat() : Object.values(NotificationType)

return notifications?.some((notification) => {
return (
types.includes(notification.type) &&
notification.recipients.some(
(recipient) => recipient.address === address && recipient.success,
)
)
})
}

private async shouldSendNotificationToPrison(
theCase: Case,
): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DefendantModule,
EventModule,
InstitutionModule,
SubpoenaModule,
UserModule,
} from '../index'
import { Notification } from './models/notification.model'
Expand All @@ -22,6 +23,7 @@ import { InternalNotificationService } from './internalNotification.service'
import { NotificationController } from './notification.controller'
import { NotificationService } from './notification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@Module({
imports: [
Expand All @@ -31,6 +33,7 @@ import { NotificationDispatchService } from './notificationDispatch.service'
MessageModule,
InstitutionModule,
UserModule,
forwardRef(() => SubpoenaModule),
forwardRef(() => CaseModule),
forwardRef(() => CourtModule),
forwardRef(() => EventModule),
Expand All @@ -43,6 +46,7 @@ import { NotificationDispatchService } from './notificationDispatch.service'
InternalNotificationService,
NotificationDispatchService,
InstitutionNotificationService,
SubpoenaNotificationService,
],
})
export class NotificationModule {}
Loading
Loading