Skip to content

Commit

Permalink
Merge branch 'main' into fix/ojoi-comments-and-web-search
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 18, 2024
2 parents 63a3e2d + 75ba90b commit fefcbd7
Show file tree
Hide file tree
Showing 47 changed files with 2,065 additions and 648 deletions.
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) {
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

0 comments on commit fefcbd7

Please sign in to comment.