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

feat(j-s): Indictment reassignment and transition to main hearing #14638

Merged
merged 5 commits into from
Apr 30, 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
@@ -0,0 +1,48 @@
'use strict'

const replaceEnum = require('sequelize-replace-enum-postgres').default

module.exports = {
up: (queryInterface) => {
return replaceEnum({
queryInterface,
tableName: 'case',
columnName: 'state',
defaultValue: 'NEW',
newValues: [
'NEW',
'DRAFT',
'WAITING_FOR_CONFIRMATION',
'SUBMITTED',
'RECEIVED',
'MAIN_HEARING', //new value
'ACCEPTED',
'REJECTED',
'DELETED',
'DISMISSED',
],
enumName: 'enum_case_state',
})
},

down: (queryInterface) => {
return replaceEnum({
queryInterface,
tableName: 'case',
columnName: 'state',
defaultValue: 'NEW',
newValues: [
'NEW',
'DRAFT',
'WAITING_FOR_CONFIRMATION',
'SUBMITTED',
'RECEIVED',
'ACCEPTED',
'REJECTED',
'DELETED',
'DISMISSED',
],
enumName: 'enum_case_state',
})
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ export class CaseController {
case CaseTransition.RETURN_INDICTMENT:
update.courtCaseNumber = ''
break
case CaseTransition.REDISTRIBUTE:
update.judgeId = null
break
}

const updatedCase = await this.caseService.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export interface UpdateCase
| 'prosecutorAppealAnnouncement'
| 'accusedPostponedAppealDate'
| 'prosecutorPostponedAppealDate'
| 'judgeId'
| 'registrarId'
| 'caseModifiedExplanation'
| 'rulingModifiedHistory'
Expand Down Expand Up @@ -169,6 +168,7 @@ export interface UpdateCase
arraignmentDate?: UpdateDateLog | null
courtDate?: UpdateDateLog | null
postponedIndefinitelyExplanation?: string | null
judgeId?: string | null
}

type DateLogKeys = keyof Pick<UpdateCase, 'arraignmentDate' | 'courtDate'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const canProsecutionUserAccessCase = (
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
].includes(theCase.state)
) {
return false
Expand Down Expand Up @@ -101,6 +102,7 @@ const canDistrictCourtUserAccessCase = (theCase: Case, user: User): boolean => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
].includes(theCase.state)
) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const getProsecutionUserCasesQueryFilter = (user: User): WhereOptions => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
{
Expand Down Expand Up @@ -88,6 +89,7 @@ const getDistrictCourtUserCasesQueryFilter = (user: User): WhereOptions => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
)
Expand Down Expand Up @@ -119,6 +121,7 @@ const getDistrictCourtUserCasesQueryFilter = (user: User): WhereOptions => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('getCasesQueryFilter', () => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
{
Expand Down Expand Up @@ -104,6 +105,7 @@ describe('getCasesQueryFilter', () => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
{
Expand Down Expand Up @@ -176,6 +178,7 @@ describe('getCasesQueryFilter', () => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
],
Expand Down Expand Up @@ -224,6 +227,7 @@ describe('getCasesQueryFilter', () => {
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
CaseState.MAIN_HEARING,
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const districtCourtJudgeTransitionRule: RolesRule = {
CaseTransition.REOPEN,
CaseTransition.RECEIVE_APPEAL,
CaseTransition.RETURN_INDICTMENT,
CaseTransition.REDISTRIBUTE,
],
canActivate: (request) => {
const theCase = request.case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,4 +938,64 @@ describe('Transition Case', () => {
)
})
})

describe('redistribute indictment', () => {
const allowedFromStates = [CaseState.RECEIVED]
const allowedFromAppealStates = [undefined]

describe.each(allowedFromStates)('state %s', (fromState) => {
it.each(allowedFromAppealStates)(
'appeal state %s - should prepare indictment for redistribution',
(fromAppealState) => {
// Act
const res = transitionCase(
CaseTransition.REDISTRIBUTE,
fromState,
fromAppealState,
)

// Assert
expect(res).toEqual({ state: CaseState.MAIN_HEARING })
},
)

it.each(Object.values(CaseAppealState))(
'appeal state %s - should not prepare indictment for redistribution',
(fromAppealState) => {
// Arrange
const act = () =>
transitionCase(
CaseTransition.REDISTRIBUTE,
fromState,
fromAppealState,
)

// Act and assert
expect(act).toThrow(ForbiddenException)
},
)
})

describe.each(
Object.values(CaseState).filter(
(state) => !allowedFromStates.includes(state),
),
)('state %s', (fromState) => {
it.each(Object.values(CaseAppealState))(
'appeal state %s - should not prepare indictment for redistribution',
(fromAppealState) => {
// Arrange
const act = () =>
transitionCase(
CaseTransition.REDISTRIBUTE,
fromState,
fromAppealState,
)

// Act and assert
expect(act).toThrow(ForbiddenException)
},
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export const caseStateMachine: Map<CaseTransition, Rule> = new Map([
to: { state: CaseState.RECEIVED },
},
],
[
CaseTransition.REDISTRIBUTE,
{
fromStates: [CaseState.RECEIVED],
fromAppealStates: [undefined],
to: { state: CaseState.MAIN_HEARING },
},
],
// APPEAL, RECEIVE_APPEAL and COMPLETE_APPEAL transitions do not affect the case state,
// but they should be blocked if case is not in a state that allows for this transition to take place
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('CaseController - Transition', () => {
${CaseTransition.DELETE} | ${CaseState.RECEIVED} | ${CaseState.DELETED}
${CaseTransition.REOPEN} | ${CaseState.ACCEPTED} | ${CaseState.RECEIVED}
${CaseTransition.RETURN_INDICTMENT} | ${CaseState.RECEIVED} | ${CaseState.DRAFT}
${CaseTransition.REDISTRIBUTE} | ${CaseState.RECEIVED} | ${CaseState.MAIN_HEARING}
`.describe(
'$transition $oldState case transitioning to $newState case',
({ transition, oldState, newState }) => {
Expand Down Expand Up @@ -191,6 +192,8 @@ describe('CaseController - Transition', () => {
transition === CaseTransition.REOPEN ? null : undefined,
courtRecordSignatureDate:
transition === CaseTransition.REOPEN ? null : undefined,
judgeId:
transition === CaseTransition.REDISTRIBUTE ? null : undefined,
},
{ where: { id: caseId }, transaction },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,11 @@ describe('mapCaseStateToTagVariant', () => {
text: m.unknown.defaultMessage,
})
})

test('should return reassignment state', () => {
expect(fn(CaseState.MAIN_HEARING, false, CaseType.INDICTMENT)).toEqual({
color: 'blue',
text: m.reassignment.defaultMessage,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ export const tagCaseState = defineMessages({
defaultMessage: 'Óþekkt',
description: 'Notað sem merki þegar mál í stöðu "Óþekkt" í málalista',
},
reassignment: {
id: 'judicial.system.core:tag_case_state.reassignment',
defaultMessage: 'Endurúthlutun',
description:
'Notað sem merki þegar mál í stöðu "Endurúthlutun" í málalista',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const mapCaseStateToTagVariant = (
return { color: 'dark', text: formatMessage(m.dismissed) }
default:
return { color: 'white', text: formatMessage(m.unknown) }
case CaseState.MAIN_HEARING:
return { color: 'blue', text: formatMessage(m.reassignment) }
}
}

Expand Down
2 changes: 2 additions & 0 deletions libs/judicial-system/types/src/lib/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export enum CaseState {
REJECTED = 'REJECTED',
DELETED = 'DELETED',
DISMISSED = 'DISMISSED',
MAIN_HEARING = 'MAIN_HEARING',
}

export enum CaseAppealState {
Expand All @@ -123,6 +124,7 @@ export enum CaseTransition {
WITHDRAW_APPEAL = 'WITHDRAW_APPEAL',
DENY_INDICTMENT = 'DENY_INDICTMENT',
RETURN_INDICTMENT = 'RETURN_INDICTMENT',
REDISTRIBUTE = 'REDISTRIBUTE',
}

/* eslint-disable @typescript-eslint/naming-convention */
Expand Down
Loading