Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsson committed Oct 17, 2024
1 parent 91959e9 commit 65203c4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { IsEnum, IsNotEmpty } from 'class-validator'

import { ApiProperty } from '@nestjs/swagger'

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

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

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

@IsNotEmpty()
@ApiProperty({ type: Subpoena })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { type Logger, LOGGER_PROVIDER } from '@island.is/logging'
import { type ConfigType } from '@island.is/nest/config'

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

import { EventService } from '../event'
import { Subpoena } from '../subpoena'
Expand All @@ -23,11 +23,6 @@ import { BaseNotificationService } from './baseNotification.service'
import { notificationModuleConfig } from './notification.config'
import { strings } from './subpoenaNotification.strings'

type subpoenaNotificationType =
| NotificationType.SERVICE_SUCCESSFUL
| NotificationType.SERVICE_FAILED
| NotificationType.DEFENDANT_SELECTED_DEFENDER

@Injectable()
export class SubpoenaNotificationService extends BaseNotificationService {
constructor(
Expand All @@ -50,22 +45,22 @@ export class SubpoenaNotificationService extends BaseNotificationService {
)
}

private getEmailContents(notificationType: subpoenaNotificationType): {
private getEmailContents(notificationType: SubpoenaNotificationType): {
subject: MessageDescriptor
body: MessageDescriptor
} {
switch (notificationType) {
case NotificationType.SERVICE_SUCCESSFUL:
case SubpoenaNotificationType.SERVICE_SUCCESSFUL:
return {
subject: strings.serviceSuccessfulSubject,
body: strings.serviceSuccessfulBody,
}
case NotificationType.SERVICE_FAILED:
case SubpoenaNotificationType.SERVICE_FAILED:
return {
subject: strings.serviceFailedSubject,
body: strings.serviceFailedBody,
}
case NotificationType.DEFENDANT_SELECTED_DEFENDER:
case SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER:
return {
subject: strings.defendantSelectedDefenderSubject,
body: strings.defendantSelectedDefenderBody,
Expand All @@ -76,7 +71,7 @@ export class SubpoenaNotificationService extends BaseNotificationService {
}

private async sendSubpoenaNotification(
notificationType: subpoenaNotificationType,
notificationType: SubpoenaNotificationType,
subpoena: Subpoena,
): Promise<unknown> {
const theCase = subpoena.case
Expand All @@ -87,23 +82,25 @@ export class SubpoenaNotificationService extends BaseNotificationService {

const hasSentSuccessfulServiceNotification = Boolean(
this.hasSentNotification(
NotificationType.SERVICE_SUCCESSFUL,
SubpoenaNotificationType.SERVICE_SUCCESSFUL,
theCase.notifications,
) && notificationType === NotificationType.SERVICE_SUCCESSFUL,
) && notificationType === SubpoenaNotificationType.SERVICE_SUCCESSFUL,
)

const hasSentFailedServiceNotification = Boolean(
this.hasSentNotification(
NotificationType.SERVICE_FAILED,
SubpoenaNotificationType.SERVICE_FAILED,
theCase.notifications,
) && notificationType === NotificationType.SERVICE_FAILED,
) && notificationType === SubpoenaNotificationType.SERVICE_FAILED,
)

const hasSendDefendantSelectedDefenderNotification = Boolean(
this.hasSentNotification(
NotificationType.DEFENDANT_SELECTED_DEFENDER,
SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER,
theCase.notifications,
) && notificationType === NotificationType.DEFENDANT_SELECTED_DEFENDER,
) &&
notificationType ===
SubpoenaNotificationType.DEFENDANT_SELECTED_DEFENDER,
)

if (
Expand Down Expand Up @@ -142,7 +139,7 @@ export class SubpoenaNotificationService extends BaseNotificationService {

private async sendEmails(
caseId: string,
notificationType: subpoenaNotificationType,
notificationType: SubpoenaNotificationType,
subject: string,
body: string,
judgeName?: string,
Expand Down Expand Up @@ -177,14 +174,11 @@ export class SubpoenaNotificationService extends BaseNotificationService {
}

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

Expand Down
2 changes: 1 addition & 1 deletion libs/judicial-system/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export {
isFailedServiceStatus,
} from './lib/defendant'
export { InstitutionType } from './lib/institution'
export { NotificationType } from './lib/notification'
export { NotificationType, SubpoenaNotificationType } from './lib/notification'

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?

Check failure on line 14 in libs/judicial-system/types/src/index.ts

View workflow job for this annotation

GitHub Actions / prepare

'"./lib/notification"' has no exported member named 'SubpoenaNotificationType'. Did you mean 'subpoenaNotificationType'?
export type { Institution } from './lib/institution'
export { EventType } from './lib/eventLog'
export { DateType } from './lib/dateLog'
Expand Down
5 changes: 5 additions & 0 deletions libs/judicial-system/types/src/lib/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export enum NotificationType {
SERVICE_FAILED = 'SERVICE_FAILED',
DEFENDANT_SELECTED_DEFENDER = 'DEFENDANT_SELECTED_DEFENDER',
}

export type subpoenaNotificationType =
| NotificationType.SERVICE_SUCCESSFUL
| NotificationType.SERVICE_FAILED
| NotificationType.DEFENDANT_SELECTED_DEFENDER

0 comments on commit 65203c4

Please sign in to comment.