Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(j-s): Handle and log updated accused postponed appeal date #16555

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
unakb marked this conversation as resolved.
Show resolved Hide resolved

appealInfo.canBeAppealed = Boolean(
!hasBeenAppealed &&
(isAppealableDecision(accusedAppealDecision) ||
isAppealableDecision(prosecutorAppealDecision)),
)

const theRulingDate = new Date(rulingDate)
appealInfo.appealDeadline = new Date(
theRulingDate.getTime() + getDays(3),
).toISOString()

unakb marked this conversation as resolved.
Show resolved Hide resolved
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
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)}`,
)
}
unakb marked this conversation as resolved.
Show resolved Hide resolved

const [numberOfAffectedRows] = await this.caseModel.update(
{ ...update },
{ where: { id: theCase.id } },
Expand Down
Loading