Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsson committed Oct 15, 2024
1 parent 48d0c4d commit f7382b5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { IsEnum, IsNotEmpty, IsUUID } from 'class-validator'
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()
@IsUUID()
@ApiProperty({ type: String })
readonly subpoenaId!: string
@ApiProperty({ type: Subpoena })
readonly subpoena!: Subpoena
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
} from '@island.is/judicial-system/message'

import { Case, CaseHasExistedGuard, CurrentCase } from '../case'
import { Subpoena } from '../subpoena'
import { CurrentSubpoena } from '../subpoena/guards/subpoena.decorator'
import { SubpoenaExistsGuard } from '../subpoena/guards/subpoenaExists.guard'
import { CaseNotificationDto } from './dto/caseNotification.dto'
import { InstitutionNotificationDto } from './dto/institutionNotification.dto'
import { SubpoenaNotificationDto } from './dto/subpoenaNotification.dto'
Expand Down Expand Up @@ -90,7 +93,7 @@ export class InternalNotificationController {

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

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

import { CaseService } from '../case'
import { EventService } from '../event'
import { SubpoenaService } from '../subpoena'
import { Subpoena, SubpoenaService } from '../subpoena'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
Expand Down Expand Up @@ -67,9 +67,8 @@ export class SubpoenaNotificationService extends BaseNotificationService {
}
}

private async getCase(subpoenaId: string) {
const subpoena = await this.subpoenaService.findBySubpoenaId(subpoenaId)
const theCase = await this.caseService.findById(subpoena.caseId)
private async getCase(caseId: string) {
const theCase = await this.caseService.findById(caseId)

if (!theCase.courtCaseNumber) {
throw new InternalServerErrorException(
Expand All @@ -82,9 +81,9 @@ export class SubpoenaNotificationService extends BaseNotificationService {

private async sendSubpoenaNotification(
notificationType: subpoenaNotificationType,
subpoenaId: string,
subpoena: Subpoena,
): Promise<unknown> {
const theCase = await this.getCase(subpoenaId)
const theCase = await this.getCase(subpoena.caseId)

const hasSentSuccessfulServiceNotification = Boolean(
this.hasSentNotification(
Expand Down Expand Up @@ -179,13 +178,10 @@ export class SubpoenaNotificationService extends BaseNotificationService {

async sendNotification(
type: NotificationType,
subpoenaId: string,
subpoena: Subpoena,
): Promise<DeliverResponse> {
try {
this.sendSubpoenaNotification(
type as subpoenaNotificationType,
subpoenaId,
)
this.sendSubpoenaNotification(type as subpoenaNotificationType, subpoena)
} catch (error) {
this.logger.error('Failed to send notification', error)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class SubpoenaService {
type: MessageType.SUBPOENA_NOTIFICATION,
body: {
type: notificationType,
subpoenaId: subpoena.subpoenaId,
subpoena,
},
},
])
Expand Down

0 comments on commit f7382b5

Please sign in to comment.