From 97b8a92dd693c73c2cf972ef6e26e603b06ce843 Mon Sep 17 00:00:00 2001 From: unakb Date: Fri, 25 Oct 2024 10:59:13 +0000 Subject: [PATCH] fix(j-s): Handle and log updated accused postponed appeal date (#16555) * fix(j-s): Stop returning appealedDate if appeal has not been made * fix(j-s): Added logs for accused postponed appeal date * Update case.transformer.spec.ts --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../interceptors/case.transformer.spec.ts | 25 +++++++++++ .../case/interceptors/case.transformer.ts | 44 +++++++++++-------- .../src/app/modules/case/case.service.ts | 17 +++++++ .../modules/case/limitedAccessCase.service.ts | 17 +++++++ 4 files changed, 85 insertions(+), 18 deletions(-) diff --git a/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts b/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts index bc0b9c64d676..fd90fb205652 100644 --- a/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts +++ b/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.spec.ts @@ -540,6 +540,31 @@ describe('getAppealInfo', () => { expect(appealInfo).toEqual({}) }) + it('should return not return appealedDate if case has not been appealed', () => { + const rulingDate = new Date().toISOString() + const theCase = { + type: CaseType.CUSTODY, + rulingDate, + appealState: undefined, + accusedAppealDecision: CaseAppealDecision.POSTPONE, + prosecutorAppealDecision: CaseAppealDecision.POSTPONE, + accusedPostponedAppealDate: '2022-06-15T19:50:08.033Z', + prosecutorPostponedAppealDate: '2022-06-15T19:50:08.033Z', + } as Case + + const appealInfo = getAppealInfo(theCase) + + expect(appealInfo).toEqual({ + canBeAppealed: true, + hasBeenAppealed: false, + appealDeadline: new Date( + new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3), + ).toISOString(), + canDefenderAppeal: true, + canProsecutorAppeal: true, + }) + }) + it('should return correct appeal info when ruling date is provided', () => { const rulingDate = new Date().toISOString() const theCase = { diff --git a/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts b/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts index f3f952dbdd2c..25b0d92fd47e 100644 --- a/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts +++ b/apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts @@ -62,36 +62,38 @@ export const getAppealInfo = (theCase: Case): AppealInfo => { const hasBeenAppealed = Boolean(appealState) + appealInfo.hasBeenAppealed = hasBeenAppealed + + if (hasBeenAppealed) { + appealInfo.appealedByRole = prosecutorPostponedAppealDate + ? UserRole.PROSECUTOR + : accusedPostponedAppealDate + ? UserRole.DEFENDER + : undefined + + appealInfo.appealedDate = + appealInfo.appealedByRole === UserRole.PROSECUTOR + ? prosecutorPostponedAppealDate ?? undefined + : accusedPostponedAppealDate ?? undefined + } + appealInfo.canBeAppealed = Boolean( !hasBeenAppealed && (isAppealableDecision(accusedAppealDecision) || isAppealableDecision(prosecutorAppealDecision)), ) + const theRulingDate = new Date(rulingDate) + appealInfo.appealDeadline = new Date( + theRulingDate.getTime() + getDays(3), + ).toISOString() + appealInfo.canProsecutorAppeal = !hasBeenAppealed && isAppealableDecision(prosecutorAppealDecision) appealInfo.canDefenderAppeal = !hasBeenAppealed && isAppealableDecision(accusedAppealDecision) - appealInfo.hasBeenAppealed = hasBeenAppealed - - appealInfo.appealedByRole = prosecutorPostponedAppealDate - ? UserRole.PROSECUTOR - : accusedPostponedAppealDate - ? UserRole.DEFENDER - : undefined - - appealInfo.appealedDate = - appealInfo.appealedByRole === UserRole.PROSECUTOR - ? prosecutorPostponedAppealDate ?? undefined - : accusedPostponedAppealDate ?? undefined - - const theRulingDate = new Date(rulingDate) - appealInfo.appealDeadline = new Date( - theRulingDate.getTime() + getDays(3), - ).toISOString() - if (appealReceivedByCourtDate) { appealInfo.statementDeadline = getStatementDeadline( new Date(appealReceivedByCourtDate), @@ -124,6 +126,12 @@ const transformRequestCase = (theCase: Case): Case => { ? Date.now() >= new Date(theCase.appealReceivedByCourtDate).getTime() + getDays(1) : false, + accusedPostponedAppealDate: appealInfo.hasBeenAppealed + ? theCase.accusedPostponedAppealDate + : undefined, + prosecutorPostponedAppealDate: appealInfo.hasBeenAppealed + ? theCase.prosecutorPostponedAppealDate + : undefined, ...appealInfo, } } diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index a3e20ea9f76a..12f19b067dd1 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -1669,6 +1669,23 @@ export class CaseService { const schedulingNewArraignmentDateForIndictmentCase = isIndictmentCase(theCase.type) && Boolean(updatedArraignmentDate) + if (update.accusedPostponedAppealDate) { + const relevantInfo = { + appealState: theCase.appealState, + accusedAppealDecision: theCase.accusedAppealDecision, + accusedPostponedAppealDate: theCase.accusedPostponedAppealDate, + prosecutorAppealDecision: theCase.prosecutorAppealDecision, + prosecutorPostponedAppealDate: theCase.prosecutorPostponedAppealDate, + update: update, + } + + this.logger.info( + `Updating accusedPostponedAppealDate in case service for case ${ + theCase.id + }. Relevant info: ${JSON.stringify(relevantInfo)}`, + ) + } + return this.sequelize .transaction(async (transaction) => { if (receivingCase) { diff --git a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts index c21a354ee45c..993a7e7406dc 100644 --- a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts @@ -314,6 +314,23 @@ export class LimitedAccessCaseService { update: LimitedAccessUpdateCase, user: TUser, ): Promise { + if (update.accusedPostponedAppealDate) { + const relevantInfo = { + appealState: theCase.appealState, + accusedAppealDecision: theCase.accusedAppealDecision, + accusedPostponedAppealDate: theCase.accusedPostponedAppealDate, + prosecutorAppealDecision: theCase.prosecutorAppealDecision, + prosecutorPostponedAppealDate: theCase.prosecutorPostponedAppealDate, + update: update, + } + + this.logger.info( + `Updating accusedPostponedAppealDate in limited access case service for case ${ + theCase.id + }. Relevant info: ${JSON.stringify(relevantInfo)}`, + ) + } + const [numberOfAffectedRows] = await this.caseModel.update( { ...update }, { where: { id: theCase.id } },