From bb5727243b96f8708f891edbc3aa1c8934eb2213 Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Wed, 8 Jan 2025 14:29:20 +0000 Subject: [PATCH 01/10] fix(j-s): refactor scheduler and seperate tasks in priv functions --- .../scheduler/src/app/app.service.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index 015d825af410..6eca589f80ee 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -24,12 +24,8 @@ export class AppService { @Inject(LOGGER_PROVIDER) private readonly logger: Logger, ) {} - async run() { - this.logger.info('Scheduler starting') - - const startTime = now() - - this.messageService + private addMessagesForIndictmentsWaitingForConfirmationToQueue() { + return this.messageService .sendMessagesToQueue([ { type: MessageType.NOTIFICATION_DISPATCH, @@ -42,6 +38,10 @@ export class AppService { // Tolerate failure, but log this.logger.error('Failed to dispatch notifications', { reason }), ) + } + + private async archiveCases() { + const startTime = now() let done = false @@ -76,6 +76,13 @@ export class AppService { !done && minutesBetween(startTime, now()) < this.config.timeToLiveMinutes ) + } + + async run() { + this.logger.info('Scheduler starting') + + await this.addMessagesForIndictmentsWaitingForConfirmationToQueue() + await this.archiveCases() this.logger.info('Scheduler done') } From e2db970a69bec8ee03d766b83b00351baa97a0bd Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Thu, 9 Jan 2025 11:33:22 +0000 Subject: [PATCH 02/10] feat(j-s): Fetch cases on arraignment date --- .../modules/case/internalCase.controller.ts | 14 +++++++ .../app/modules/case/internalCase.service.ts | 18 +++++++++ .../src/app/modules/event/event.service.ts | 1 + .../scheduler/src/app/app.service.ts | 38 ++++++++++++++++++- 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index 5b65a20a1abe..ba6d2d45a673 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -77,6 +77,20 @@ export class InternalCaseController { return this.internalCaseService.archive() } + @Get('cases/arraignmentDate/:arraignmentDate') + @ApiOkResponse({ + type: Case, + isArray: true, + description: 'Fetch all cases that have court arrangement for a given date', + }) + getCasesAtArraignmentDate(@Param('date') date: Date): Promise { + this.logger.debug( + `Getting all cases that have court arrangement at ${date}`, + ) + + return this.internalCaseService.getAllCasesAtArraignmentDate(date) + } + @Get('cases/indictments/defendant/:defendantNationalId') @ApiOkResponse({ type: Case, diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index d0e54067af7f..5e7f66ce4372 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -27,6 +27,7 @@ import { CaseOrigin, CaseState, CaseType, + dateTypes, EventType, isIndictmentCase, isProsecutionUser, @@ -520,6 +521,23 @@ export class InternalCaseService { return { caseArchived: true } } + async getAllCasesAtArraignmentDate(date: Date): Promise { + const cases = this.caseModel.findAll({ + include: [ + { + model: DateLog, + as: 'dateLogs', + where: { + date_type: 'ARRAIGNMENT_DATE', // or court date? + date: date, + }, + required: true, + }, + ], + }) + return cases + } + async deliverProsecutorToCourt( theCase: Case, user: TUser, diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index 9ab7679e86ae..be933e56f5b7 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -39,6 +39,7 @@ const errorEmojis = [ ':x:', ] +// TODO: Add fyrirtökur schedule const caseEvent: Record = { [CaseTransition.ACCEPT]: ':white_check_mark: Samþykkt', [CaseTransition.APPEAL]: ':judge: Kæra', diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index 6eca589f80ee..62ec66bf42c2 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -1,6 +1,6 @@ import fetch from 'node-fetch' -import { Inject, Injectable } from '@nestjs/common' +import { BadGatewayException, Inject, Injectable } from '@nestjs/common' import { type Logger, LOGGER_PROVIDER } from '@island.is/logging' import { type ConfigType } from '@island.is/nest/config' @@ -78,11 +78,47 @@ export class AppService { ) } + // New arraignments can be added with only few hour notice + // Maybe we should then also send an updated summary alert when arraignment is added today + private async postDailyArraignmentsSummary() { + // Fetch all court arrangement happening today + const getCasesAtArraignmentDate = async () => { + const today = new Date() + + try { + const res = await fetch( + `${this.config.backendUrl}/api/internal/cases/arraignmentDate/${today}`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + authorization: `Bearer ${this.config.backendAccessToken}`, + }, + }, + ) + + if (!res.ok) { + throw new BadGatewayException( + 'Unexpected error occurred while fetching cases', + ) + } + return res.json() + // send the aggregated notification for the cases: eventService -> new endpoint + } catch (error) { + throw new BadGatewayException(`Failed to fetch cases: ${error.message}`) + } + } + + const cases = await getCasesAtArraignmentDate() + console.log({cases}) + } + async run() { this.logger.info('Scheduler starting') await this.addMessagesForIndictmentsWaitingForConfirmationToQueue() await this.archiveCases() + await this.postDailyArraignmentsSummary() this.logger.info('Scheduler done') } From 78657d346acd1f0e04fce6083621609a3dfc9dda Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Thu, 9 Jan 2025 15:22:30 +0000 Subject: [PATCH 03/10] chore(j-s): configure slack message --- .../modules/case/internalCase.controller.ts | 15 ++++-- .../app/modules/case/internalCase.service.ts | 16 +++++-- .../case/limitedAccessCase.controller.ts | 2 - .../src/app/modules/event/event.service.ts | 45 ++++++++++++++++++ .../scheduler/src/app/app.service.ts | 47 ++++++++----------- 5 files changed, 85 insertions(+), 40 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index ba6d2d45a673..db50196ded65 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -77,18 +77,23 @@ export class InternalCaseController { return this.internalCaseService.archive() } - @Get('cases/arraignmentDate/:arraignmentDate') + @Post('cases/postHearingArrangements/:date') @ApiOkResponse({ type: Case, isArray: true, - description: 'Fetch all cases that have court arrangement for a given date', + description: + 'Fetch all cases that have court hearing arrangements for a given date', }) - getCasesAtArraignmentDate(@Param('date') date: Date): Promise { + async postHearingArrangements(@Param('date') date: Date): Promise { this.logger.debug( - `Getting all cases that have court arrangement at ${date}`, + `Post internal summary of all cases that have court hearing arrangement at ${date}`, ) - return this.internalCaseService.getAllCasesAtArraignmentDate(date) + const cases = await this.internalCaseService.getCaseHearingArrangements( + date, + ) + await this.eventService.postDailyHearingArrangementEvents(date, cases) + return cases } @Get('cases/indictments/defendant/:defendantNationalId') diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index 5e7f66ce4372..e710b050a14b 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -521,21 +521,27 @@ export class InternalCaseService { return { caseArchived: true } } - async getAllCasesAtArraignmentDate(date: Date): Promise { - const cases = this.caseModel.findAll({ + async getCaseHearingArrangements(date: Date): Promise { + const startOfDay = new Date(date.setHours(0, 0, 0, 0)) // Set to 00:00:00 + const endOfDay = new Date(date.setHours(23, 59, 59, 999)) // Set to 23:59:59 + + return this.caseModel.findAll({ include: [ { model: DateLog, as: 'dateLogs', where: { - date_type: 'ARRAIGNMENT_DATE', // or court date? - date: date, + date_type: ['ARRAIGNMENT_DATE', 'COURT_DATE'], + date: { + [Op.gte]: startOfDay, + [Op.lte]: endOfDay, + }, }, required: true, }, ], + order: [[{ model: DateLog, as: 'dateLogs' }, 'date', 'ASC']], }) - return cases } async deliverProsecutorToCourt( diff --git a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts index 22e6be63d5e0..17cdb20a358e 100644 --- a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts @@ -30,7 +30,6 @@ import type { User as TUser } from '@island.is/judicial-system/types' import { CaseState, CaseType, - DefendantEventType, indictmentCases, investigationCases, restrictionCases, @@ -39,7 +38,6 @@ import { import { nowFactory } from '../../factories' import { defenderRule, prisonSystemStaffRule } from '../../guards' -import { DefendantService } from '../defendant' import { EventService } from '../event' import { User } from '../user' import { TransitionCaseDto } from './dto/transitionCase.dto' diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index be933e56f5b7..00ee3b11a39c 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -174,6 +174,51 @@ export class EventService { } } + async postDailyHearingArrangementEvents(date: Date, cases: Case[]) { + const title = `:judge: Fyrirtökur ${formatDate(date)}` + + const arrangementTexts = cases.map((theCase) => { + return `>${theCase.courtCaseNumber}: ${ + formatDate( + DateLog.courtDate(theCase.dateLogs)?.date ?? + DateLog.arraignmentDate(theCase.dateLogs)?.date, + 'Pp', + ) ?? date + }` + }) + + const arrangementSummary = + arrangementTexts.length > 0 + ? arrangementTexts.join('\n') + : 'Engar fyrirtökur á dagskrá' + + try { + if (!this.config.url) { + return + } + + await fetch(`${this.config.url}`, { + method: 'POST', + headers: { 'Content-type': 'application/json' }, + body: JSON.stringify({ + blocks: [ + { + type: 'section', + text: { + type: 'mrkdwn', + text: `*${title}*\n${arrangementSummary}`, + }, + }, + ], + }), + }) + } catch (error) { + this.logger.error(`Failed to post court hearing arrangement summary`, { + error, + }) + } + } + async postErrorEvent( message: string, info: { [key: string]: string | boolean | Date | undefined }, diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index 62ec66bf42c2..5d3b8a1ca474 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -78,39 +78,30 @@ export class AppService { ) } - // New arraignments can be added with only few hour notice - // Maybe we should then also send an updated summary alert when arraignment is added today private async postDailyArraignmentsSummary() { - // Fetch all court arrangement happening today - const getCasesAtArraignmentDate = async () => { - const today = new Date() - - try { - const res = await fetch( - `${this.config.backendUrl}/api/internal/cases/arraignmentDate/${today}`, - { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - authorization: `Bearer ${this.config.backendAccessToken}`, - }, +// TODO: set to new Date() + const today = new Date(2025, 0, 8) + try { + const res = await fetch( + `${this.config.backendUrl}/api/internal/cases/postHearingArrangements/${today}`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + authorization: `Bearer ${this.config.backendAccessToken}`, }, - ) + }, + ) - if (!res.ok) { - throw new BadGatewayException( - 'Unexpected error occurred while fetching cases', - ) - } - return res.json() - // send the aggregated notification for the cases: eventService -> new endpoint - } catch (error) { - throw new BadGatewayException(`Failed to fetch cases: ${error.message}`) + if (!res.ok) { + throw new BadGatewayException( + 'Unexpected error occurred while fetching cases', + ) } + return res.json() + } catch (error) { + throw new BadGatewayException(`Failed to fetch cases: ${error.message}`) } - - const cases = await getCasesAtArraignmentDate() - console.log({cases}) } async run() { From 860eab3836d21caf0f28a28d22b6f3174272f3db Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Thu, 9 Jan 2025 15:58:37 +0000 Subject: [PATCH 04/10] fix(j-s): refactoring + only showing timestamp in summary --- .../backend/src/app/modules/event/event.service.ts | 2 +- apps/judicial-system/scheduler/src/app/app.service.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index 00ee3b11a39c..5ec02ca54048 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -182,7 +182,7 @@ export class EventService { formatDate( DateLog.courtDate(theCase.dateLogs)?.date ?? DateLog.arraignmentDate(theCase.dateLogs)?.date, - 'Pp', + 'p', ) ?? date }` }) diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index 5d3b8a1ca474..d220df13912d 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -78,9 +78,8 @@ export class AppService { ) } - private async postDailyArraignmentsSummary() { -// TODO: set to new Date() - const today = new Date(2025, 0, 8) + private async postDailyHearingArrangementSummary() { + const today = new Date() try { const res = await fetch( `${this.config.backendUrl}/api/internal/cases/postHearingArrangements/${today}`, @@ -109,7 +108,7 @@ export class AppService { await this.addMessagesForIndictmentsWaitingForConfirmationToQueue() await this.archiveCases() - await this.postDailyArraignmentsSummary() + await this.postDailyHearingArrangementSummary() this.logger.info('Scheduler done') } From ff8d3dba01c1f9e5f65cd35f86a90b671a68ba0a Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Fri, 10 Jan 2025 10:01:01 +0000 Subject: [PATCH 05/10] fix(j-s): cleanup and minor refactor --- .../backend/src/app/modules/case/internalCase.controller.ts | 3 +-- .../backend/src/app/modules/case/internalCase.service.ts | 4 ++-- .../backend/src/app/modules/event/event.service.ts | 3 +-- apps/judicial-system/scheduler/src/app/app.service.ts | 1 - 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index db50196ded65..1087fb20dd1f 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -84,7 +84,7 @@ export class InternalCaseController { description: 'Fetch all cases that have court hearing arrangements for a given date', }) - async postHearingArrangements(@Param('date') date: Date): Promise { + async postHearingArrangements(@Param('date') date: Date): Promise { this.logger.debug( `Post internal summary of all cases that have court hearing arrangement at ${date}`, ) @@ -93,7 +93,6 @@ export class InternalCaseController { date, ) await this.eventService.postDailyHearingArrangementEvents(date, cases) - return cases } @Get('cases/indictments/defendant/:defendantNationalId') diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index e710b050a14b..cac1caad8696 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -522,8 +522,8 @@ export class InternalCaseService { } async getCaseHearingArrangements(date: Date): Promise { - const startOfDay = new Date(date.setHours(0, 0, 0, 0)) // Set to 00:00:00 - const endOfDay = new Date(date.setHours(23, 59, 59, 999)) // Set to 23:59:59 + const startOfDay = new Date(date.setHours(0, 0, 0, 0)) + const endOfDay = new Date(date.setHours(23, 59, 59, 999)) return this.caseModel.findAll({ include: [ diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index 5ec02ca54048..2b5170a050af 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -39,7 +39,6 @@ const errorEmojis = [ ':x:', ] -// TODO: Add fyrirtökur schedule const caseEvent: Record = { [CaseTransition.ACCEPT]: ':white_check_mark: Samþykkt', [CaseTransition.APPEAL]: ':judge: Kæra', @@ -190,7 +189,7 @@ export class EventService { const arrangementSummary = arrangementTexts.length > 0 ? arrangementTexts.join('\n') - : 'Engar fyrirtökur á dagskrá' + : '>Engar fyrirtökur á dagskrá' try { if (!this.config.url) { diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index d220df13912d..dee18a348a39 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -97,7 +97,6 @@ export class AppService { 'Unexpected error occurred while fetching cases', ) } - return res.json() } catch (error) { throw new BadGatewayException(`Failed to fetch cases: ${error.message}`) } From a45d8173d4dfd5db406964c8a24d694adee756cd Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Fri, 10 Jan 2025 10:01:01 +0000 Subject: [PATCH 06/10] fix(j-s): cleanup and minor refactor --- .../backend/src/app/modules/case/internalCase.controller.ts | 3 +-- .../backend/src/app/modules/case/internalCase.service.ts | 5 ++--- .../backend/src/app/modules/event/event.service.ts | 3 +-- apps/judicial-system/scheduler/src/app/app.service.ts | 1 - 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index db50196ded65..1087fb20dd1f 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -84,7 +84,7 @@ export class InternalCaseController { description: 'Fetch all cases that have court hearing arrangements for a given date', }) - async postHearingArrangements(@Param('date') date: Date): Promise { + async postHearingArrangements(@Param('date') date: Date): Promise { this.logger.debug( `Post internal summary of all cases that have court hearing arrangement at ${date}`, ) @@ -93,7 +93,6 @@ export class InternalCaseController { date, ) await this.eventService.postDailyHearingArrangementEvents(date, cases) - return cases } @Get('cases/indictments/defendant/:defendantNationalId') diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index e710b050a14b..6270725b5314 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -27,7 +27,6 @@ import { CaseOrigin, CaseState, CaseType, - dateTypes, EventType, isIndictmentCase, isProsecutionUser, @@ -522,8 +521,8 @@ export class InternalCaseService { } async getCaseHearingArrangements(date: Date): Promise { - const startOfDay = new Date(date.setHours(0, 0, 0, 0)) // Set to 00:00:00 - const endOfDay = new Date(date.setHours(23, 59, 59, 999)) // Set to 23:59:59 + const startOfDay = new Date(date.setHours(0, 0, 0, 0)) + const endOfDay = new Date(date.setHours(23, 59, 59, 999)) return this.caseModel.findAll({ include: [ diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index 5ec02ca54048..2b5170a050af 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -39,7 +39,6 @@ const errorEmojis = [ ':x:', ] -// TODO: Add fyrirtökur schedule const caseEvent: Record = { [CaseTransition.ACCEPT]: ':white_check_mark: Samþykkt', [CaseTransition.APPEAL]: ':judge: Kæra', @@ -190,7 +189,7 @@ export class EventService { const arrangementSummary = arrangementTexts.length > 0 ? arrangementTexts.join('\n') - : 'Engar fyrirtökur á dagskrá' + : '>Engar fyrirtökur á dagskrá' try { if (!this.config.url) { diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index d220df13912d..dee18a348a39 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -97,7 +97,6 @@ export class AppService { 'Unexpected error occurred while fetching cases', ) } - return res.json() } catch (error) { throw new BadGatewayException(`Failed to fetch cases: ${error.message}`) } From 239f60e91f6ecc856706f0bc05bbbf2adb950cd3 Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Fri, 10 Jan 2025 14:42:49 +0000 Subject: [PATCH 07/10] fix(j-s): tests --- apps/judicial-system/scheduler/src/app/test/run.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/judicial-system/scheduler/src/app/test/run.spec.ts b/apps/judicial-system/scheduler/src/app/test/run.spec.ts index df149409eeab..5d8810b29ec9 100644 --- a/apps/judicial-system/scheduler/src/app/test/run.spec.ts +++ b/apps/judicial-system/scheduler/src/app/test/run.spec.ts @@ -28,6 +28,7 @@ describe('AppService - Run', () => { beforeEach(() => { mockNow.mockClear() mockFetch.mockClear() + mockNow.mockReturnValue(new Date('2020-01-01T00:01:00.000Z')) givenWhenThen = async (): Promise => { @@ -75,7 +76,7 @@ describe('AppService - Run', () => { body: { type: 'INDICTMENTS_WAITING_FOR_CONFIRMATION' }, }, ]) - expect(fetch).toHaveBeenCalledTimes(3) + expect(fetch).toHaveBeenCalledTimes(4) expect(fetch).toHaveBeenCalledWith( `${appModuleConfig().backendUrl}/api/internal/cases/archive`, { @@ -102,8 +103,8 @@ describe('AppService - Run', () => { await givenWhenThen() }) - it('should call the backend twice', () => { - expect(fetch).toHaveBeenCalledTimes(2) + it('should call the backend three times', () => { + expect(fetch).toHaveBeenCalledTimes(3) }) }) From d792494fe8be3b0027e249f30d6506d538013b58 Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Fri, 10 Jan 2025 15:52:31 +0000 Subject: [PATCH 08/10] fix(j-s): how we init the param date --- .../scheduler/src/app/app.service.ts | 4 +-- .../scheduler/src/app/test/run.spec.ts | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index dee18a348a39..41fb119a137d 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -79,8 +79,8 @@ export class AppService { } private async postDailyHearingArrangementSummary() { - const today = new Date() - try { + const today = now() + try { const res = await fetch( `${this.config.backendUrl}/api/internal/cases/postHearingArrangements/${today}`, { diff --git a/apps/judicial-system/scheduler/src/app/test/run.spec.ts b/apps/judicial-system/scheduler/src/app/test/run.spec.ts index 5d8810b29ec9..3ebbf7fa9edd 100644 --- a/apps/judicial-system/scheduler/src/app/test/run.spec.ts +++ b/apps/judicial-system/scheduler/src/app/test/run.spec.ts @@ -87,6 +87,18 @@ describe('AppService - Run', () => { }, }, ) + expect(fetch).toHaveBeenCalledWith( + `${ + appModuleConfig().backendUrl + }/api/internal/cases/postHearingArrangements/${new Date('2020-01-01T00:01:00.000Z')}`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + authorization: `Bearer ${appModuleConfig().backendAccessToken}`, + }, + }, + ) }) }) @@ -103,8 +115,17 @@ describe('AppService - Run', () => { await givenWhenThen() }) - it('should call the backend three times', () => { - expect(fetch).toHaveBeenCalledTimes(3) + it('should attempt archiving twice', () => { + expect(fetch).toHaveBeenNthCalledWith( + 1, + `${appModuleConfig().backendUrl}/api/internal/cases/archive`, + expect.any(Object), + ) + expect(fetch).toHaveBeenNthCalledWith( + 2, + `${appModuleConfig().backendUrl}/api/internal/cases/archive`, + expect.any(Object), + ) }) }) From 27e2ecf836ac871171255003a3fb2c36b5af2a0c Mon Sep 17 00:00:00 2001 From: andes-it Date: Fri, 10 Jan 2025 16:04:09 +0000 Subject: [PATCH 09/10] chore: nx format:write update dirty files --- apps/judicial-system/scheduler/src/app/app.service.ts | 2 +- apps/judicial-system/scheduler/src/app/test/run.spec.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index 41fb119a137d..e906154c3968 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -80,7 +80,7 @@ export class AppService { private async postDailyHearingArrangementSummary() { const today = now() - try { + try { const res = await fetch( `${this.config.backendUrl}/api/internal/cases/postHearingArrangements/${today}`, { diff --git a/apps/judicial-system/scheduler/src/app/test/run.spec.ts b/apps/judicial-system/scheduler/src/app/test/run.spec.ts index 3ebbf7fa9edd..81a6d55d3e13 100644 --- a/apps/judicial-system/scheduler/src/app/test/run.spec.ts +++ b/apps/judicial-system/scheduler/src/app/test/run.spec.ts @@ -90,7 +90,9 @@ describe('AppService - Run', () => { expect(fetch).toHaveBeenCalledWith( `${ appModuleConfig().backendUrl - }/api/internal/cases/postHearingArrangements/${new Date('2020-01-01T00:01:00.000Z')}`, + }/api/internal/cases/postHearingArrangements/${new Date( + '2020-01-01T00:01:00.000Z', + )}`, { method: 'POST', headers: { From b89ff4a00074143b5064369364747784a6c90233 Mon Sep 17 00:00:00 2001 From: Thorhildur Thorleiksdottir Date: Mon, 13 Jan 2025 16:30:47 +0000 Subject: [PATCH 10/10] fix(j-s): add date as a request body property rather than url param --- .../app/modules/case/internalCase.controller.ts | 14 +++++--------- .../scheduler/src/app/app.service.ts | 5 +++-- .../scheduler/src/app/test/run.spec.ts | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index 1087fb20dd1f..565c544b77c5 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -77,20 +77,16 @@ export class InternalCaseController { return this.internalCaseService.archive() } - @Post('cases/postHearingArrangements/:date') - @ApiOkResponse({ - type: Case, - isArray: true, - description: - 'Fetch all cases that have court hearing arrangements for a given date', - }) - async postHearingArrangements(@Param('date') date: Date): Promise { + @Post('cases/postHearingArrangements') + async postHearingArrangements( + @Body() { date }: { date: Date }, + ): Promise { this.logger.debug( `Post internal summary of all cases that have court hearing arrangement at ${date}`, ) const cases = await this.internalCaseService.getCaseHearingArrangements( - date, + new Date(date), ) await this.eventService.postDailyHearingArrangementEvents(date, cases) } diff --git a/apps/judicial-system/scheduler/src/app/app.service.ts b/apps/judicial-system/scheduler/src/app/app.service.ts index 41fb119a137d..7a8a1db30411 100644 --- a/apps/judicial-system/scheduler/src/app/app.service.ts +++ b/apps/judicial-system/scheduler/src/app/app.service.ts @@ -80,15 +80,16 @@ export class AppService { private async postDailyHearingArrangementSummary() { const today = now() - try { + try { const res = await fetch( - `${this.config.backendUrl}/api/internal/cases/postHearingArrangements/${today}`, + `${this.config.backendUrl}/api/internal/cases/postHearingArrangements`, { method: 'POST', headers: { 'Content-Type': 'application/json', authorization: `Bearer ${this.config.backendAccessToken}`, }, + body: JSON.stringify({ date: today }), }, ) diff --git a/apps/judicial-system/scheduler/src/app/test/run.spec.ts b/apps/judicial-system/scheduler/src/app/test/run.spec.ts index 3ebbf7fa9edd..c9ac0f76efea 100644 --- a/apps/judicial-system/scheduler/src/app/test/run.spec.ts +++ b/apps/judicial-system/scheduler/src/app/test/run.spec.ts @@ -90,13 +90,14 @@ describe('AppService - Run', () => { expect(fetch).toHaveBeenCalledWith( `${ appModuleConfig().backendUrl - }/api/internal/cases/postHearingArrangements/${new Date('2020-01-01T00:01:00.000Z')}`, + }/api/internal/cases/postHearingArrangements`, { method: 'POST', headers: { 'Content-Type': 'application/json', authorization: `Bearer ${appModuleConfig().backendAccessToken}`, }, + body: JSON.stringify({ date: new Date('2020-01-01T00:01:00.000Z') }), }, ) })