Skip to content

Commit

Permalink
fix(j-s): Handle and log updated accused postponed appeal date (#16555)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
unakb and kodiakhq[bot] authored Oct 25, 2024
1 parent ab72373 commit 97b8a92
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
}
}
Expand Down
17 changes: 17 additions & 0 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,23 @@ export class LimitedAccessCaseService {
update: LimitedAccessUpdateCase,
user: TUser,
): Promise<Case> {
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 } },
Expand Down

0 comments on commit 97b8a92

Please sign in to comment.