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

refactor(j-s): Transition Side Effects #16660

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 @@ -307,27 +307,15 @@ export class CaseController {

let update: UpdateCase = transitionCase(
transition.transition,
theCase.type,
theCase.state,
theCase.appealState,
theCase,
user,
)

switch (transition.transition) {
case CaseTransition.DELETE:
update.parentCaseId = null
break
case CaseTransition.SUBMIT:
if (isIndictmentCase(theCase.type)) {
update.indictmentDeniedExplanation = null
}
break
case CaseTransition.ACCEPT:
case CaseTransition.REJECT:
case CaseTransition.DISMISS:
case CaseTransition.COMPLETE:
update.rulingDate = isIndictmentCase(theCase.type)
? nowFactory()
: theCase.courtEndTime
update.rulingDate = theCase.courtEndTime

// Handle appealed in court
if (
Expand All @@ -345,27 +333,14 @@ export class CaseController {
...update,
...transitionCase(
CaseTransition.APPEAL,
theCase.type,
update.state ?? theCase.state,
update.appealState ?? theCase.appealState,
theCase,
user,
update.state,
update.appealState,
),
}
}
break
case CaseTransition.REOPEN:
update.rulingDate = null
update.courtRecordSignatoryId = null
update.courtRecordSignatureDate = null
break
// TODO: Consider changing the names of the postponed appeal date variables
// as they are now also used when the case is appealed in court
case CaseTransition.APPEAL:
// The only roles that can appeal a case here are prosecutor roles
update.prosecutorPostponedAppealDate = nowFactory()
break
case CaseTransition.RECEIVE_APPEAL:
update.appealReceivedByCourtDate = nowFactory()
break
case CaseTransition.COMPLETE_APPEAL:
if (
isRestrictionCase(theCase.type) &&
Expand All @@ -389,32 +364,6 @@ export class CaseController {
update.validToDate = nowFactory()
}
}
break
case CaseTransition.WITHDRAW_APPEAL:
// We only want to set the appeal ruling decision if the
// case has already been received.
// Otherwise the court of appeals never knew of the appeal in
// the first place so it remains withdrawn without a decision.
if (
!theCase.appealRulingDecision &&
theCase.appealState === CaseAppealState.RECEIVED
) {
update.appealRulingDecision = CaseAppealRulingDecision.DISCONTINUED
}
break
case CaseTransition.ASK_FOR_CONFIRMATION:
update.indictmentReturnedExplanation = null
break
case CaseTransition.RETURN_INDICTMENT:
update.courtCaseNumber = null
update.indictmentHash = null
break
case CaseTransition.ASK_FOR_CANCELLATION:
if (theCase.indictmentDecision) {
throw new ForbiddenException(
`Cannot ask for cancellation of an indictment that is already in progress at the district court`,
)
}
}

const updatedCase = await this.caseService.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1691,9 +1691,10 @@ export class CaseService {
if (receivingCase) {
update.state = transitionCase(
CaseTransition.RECEIVE,
theCase.type,
theCase.state,
theCase.appealState,
theCase,
user,
update.state,
update.appealState,
).state
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,10 @@ export class LimitedAccessCaseController {

const update: LimitedAccessUpdateCase = transitionCase(
transition.transition,
theCase.type,
theCase.state,
theCase.appealState,
theCase,
user,
)

if (update.appealState === CaseAppealState.APPEALED) {
update.accusedPostponedAppealDate = nowFactory()
}

if (
transition.transition === CaseTransition.WITHDRAW_APPEAL &&
!theCase.appealRulingDecision &&
theCase.appealState === CaseAppealState.RECEIVED
) {
update.appealRulingDecision = CaseAppealRulingDecision.DISCONTINUED
}

const updatedCase = await this.limitedAccessCaseService.update(
theCase,
update,
Expand Down
Loading
Loading