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 54cd32b08d75..bc0b9c64d676 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 @@ -14,7 +14,7 @@ import { Defendant } from '../../defendant' import { Case } from '../models/case.model' import { getAppealInfo, - getDefendantsInfo, + getIndictmentDefendantsInfo, getIndictmentInfo, transformCase, } from './case.transformer' @@ -685,23 +685,25 @@ describe('getIndictmentInfo', () => { }) }) -describe('getDefentandInfo', () => { - it('should add verdict appeal deadline for defendants with verdict view date', () => { +describe('getIndictmentDefendantsInfo', () => { + it('should add verdict appeal deadline and expiry for defendants with verdict view date', () => { const defendants = [ { verdictViewDate: '2022-06-15T19:50:08.033Z' } as Defendant, { verdictViewDate: undefined } as Defendant, ] - const defendantsInfo = getDefendantsInfo(defendants) + const defendantsInfo = getIndictmentDefendantsInfo(defendants) expect(defendantsInfo).toEqual([ { verdictViewDate: '2022-06-15T19:50:08.033Z', verdictAppealDeadline: '2022-07-13T19:50:08.033Z', + isVerdictAppealDeadlineExpired: true, }, { verdictViewDate: undefined, verdictAppealDeadline: undefined, + isVerdictAppealDeadlineExpired: false, }, ]) }) 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 4accbfef14f9..f3f952dbdd2c 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 @@ -169,7 +169,9 @@ export const getIndictmentInfo = ( return indictmentInfo } -export const getDefendantsInfo = (defendants: Defendant[] | undefined) => { +export const getIndictmentDefendantsInfo = ( + defendants: Defendant[] | undefined, +) => { return defendants?.map((defendant) => { const { verdictViewDate } = defendant const verdictAppealDeadline = verdictViewDate @@ -177,10 +179,14 @@ export const getDefendantsInfo = (defendants: Defendant[] | undefined) => { new Date(verdictViewDate).getTime() + getDays(28), ).toISOString() : undefined + const isVerdictAppealDeadlineExpired = verdictAppealDeadline + ? Date.now() >= new Date(verdictAppealDeadline).getTime() + : false return { ...defendant, verdictAppealDeadline, + isVerdictAppealDeadlineExpired, } }) } @@ -194,7 +200,7 @@ const transformIndictmentCase = (theCase: Case): Case => { theCase.defendants, theCase.eventLogs, ), - defendants: getDefendantsInfo(theCase.defendants), + defendants: getIndictmentDefendantsInfo(theCase.defendants), } } diff --git a/apps/judicial-system/api/src/app/modules/case/interceptors/limitedAccessCase.transformer.ts b/apps/judicial-system/api/src/app/modules/case/interceptors/limitedAccessCase.transformer.ts index c7b4828ba946..befd415e8905 100644 --- a/apps/judicial-system/api/src/app/modules/case/interceptors/limitedAccessCase.transformer.ts +++ b/apps/judicial-system/api/src/app/modules/case/interceptors/limitedAccessCase.transformer.ts @@ -1,10 +1,15 @@ import { CaseState, completedRequestCaseStates, + isRequestCase, RequestSharedWithDefender, } from '@island.is/judicial-system/types' import { Case } from '../models/case.model' +import { + getIndictmentDefendantsInfo, + getIndictmentInfo, +} from './case.transformer' const RequestSharedWithDefenderAllowedStates: { [key in RequestSharedWithDefender]: CaseState[] @@ -39,7 +44,7 @@ export const canDefenderViewRequest = (theCase: Case) => { ) } -export const transformLimitedAccessCase = (theCase: Case): Case => { +const transformRequestCase = (theCase: Case): Case => { return { ...theCase, caseResentExplanation: canDefenderViewRequest(theCase) @@ -47,3 +52,26 @@ export const transformLimitedAccessCase = (theCase: Case): Case => { : undefined, } } + +const transformIndictmentCase = (theCase: Case): Case => { + const { indictmentRulingDecision, rulingDate, defendants, eventLogs } = + theCase + return { + ...theCase, + ...getIndictmentInfo( + indictmentRulingDecision, + rulingDate, + defendants, + eventLogs, + ), + defendants: getIndictmentDefendantsInfo(theCase.defendants), + } +} + +export const transformLimitedAccessCase = (theCase: Case): Case => { + if (isRequestCase(theCase.type)) { + return transformRequestCase(theCase) + } + + return transformIndictmentCase(theCase) +} diff --git a/apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts b/apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts index 5b509b4dba2b..b592ccccb6e9 100644 --- a/apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts +++ b/apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts @@ -72,6 +72,9 @@ export class Defendant { @Field(() => String, { nullable: true }) readonly verdictAppealDeadline?: string + @Field(() => Boolean, { nullable: true }) + readonly isVerdictAppealDeadlineExpired?: boolean + @Field(() => DefenderChoice, { nullable: true }) readonly defenderChoice?: DefenderChoice diff --git a/apps/judicial-system/web/src/components/FormProvider/case.graphql b/apps/judicial-system/web/src/components/FormProvider/case.graphql index 5f2d3f3ec668..752280bf625c 100644 --- a/apps/judicial-system/web/src/components/FormProvider/case.graphql +++ b/apps/judicial-system/web/src/components/FormProvider/case.graphql @@ -30,6 +30,7 @@ query Case($input: CaseQueryInput!) { serviceRequirement verdictViewDate verdictAppealDeadline + isVerdictAppealDeadlineExpired subpoenaType subpoenas { id diff --git a/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql b/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql index d93e997e27c0..f58b990fc571 100644 --- a/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql +++ b/apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql @@ -34,8 +34,10 @@ query LimitedAccessCase($input: CaseQueryInput!) { defenderEmail defenderPhoneNumber defenderChoice + serviceRequirement verdictViewDate verdictAppealDeadline + isVerdictAppealDeadlineExpired subpoenas { id created @@ -159,6 +161,8 @@ query LimitedAccessCase($input: CaseQueryInput!) { indictmentRulingDecision indictmentCompletedDate indictmentReviewDecision + indictmentVerdictViewedByAll + indictmentVerdictAppealDeadlineExpired indictmentReviewer { id name diff --git a/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.spec.ts b/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.spec.ts index 5333f47cbe61..816e28ff4388 100644 --- a/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.spec.ts +++ b/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.spec.ts @@ -15,10 +15,12 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is REQUIRED and verdictAppealDeadline is not provided', () => { const verdictAppealDeadline = undefined + const isVerdictAppealDeadlineExpired = false const serviceRequirement = ServiceRequirement.REQUIRED const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) @@ -29,10 +31,13 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is NOT_APPLICABLE and verdictAppealDeadline is not provided', () => { const verdictAppealDeadline = undefined + const isVerdictAppealDeadlineExpired = false + const serviceRequirement = ServiceRequirement.NOT_APPLICABLE const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) @@ -43,10 +48,12 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is NOT_REQUIRED', () => { const verdictAppealDeadline = undefined + const isVerdictAppealDeadlineExpired = false const serviceRequirement = ServiceRequirement.NOT_REQUIRED const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) @@ -57,10 +64,12 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is REQUIRED and appeal expiration date is in the future', () => { const verdictAppealDeadline = '2024-08-05' + const isVerdictAppealDeadlineExpired = false const serviceRequirement = ServiceRequirement.REQUIRED const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) @@ -72,10 +81,12 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is NOT_APPLICABLE and appeal expiration date is in the future', () => { const verdictAppealDeadline = '2024-08-05' + const isVerdictAppealDeadlineExpired = false const serviceRequirement = ServiceRequirement.NOT_APPLICABLE const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) @@ -87,10 +98,12 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is REQUIRED and appeal expiration date is in the past', () => { const verdictAppealDeadline = '2024-07-07' + const isVerdictAppealDeadlineExpired = true const serviceRequirement = ServiceRequirement.REQUIRED const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) @@ -102,10 +115,12 @@ describe('DefendantInfo', () => { test('should return the correct string if serviceRequirement is NOT_APPLICABLE and appeal expiration date is in the past', () => { const verdictAppealDeadline = '2024-07-07' + const isVerdictAppealDeadlineExpired = true const serviceRequirement = ServiceRequirement.NOT_APPLICABLE const dataSections = getAppealExpirationInfo( verdictAppealDeadline, + isVerdictAppealDeadlineExpired, serviceRequirement, ) diff --git a/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx b/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx index 1666858b4342..dbbade62a3cb 100644 --- a/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx +++ b/apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx @@ -38,6 +38,7 @@ interface DefendantInfoProps { export const getAppealExpirationInfo = ( verdictAppealDeadline?: string | null, + isVerdictAppealDeadlineExpired?: boolean | null, serviceRequirement?: ServiceRequirement | null, ) => { if (serviceRequirement === ServiceRequirement.NOT_REQUIRED) { @@ -48,14 +49,11 @@ export const getAppealExpirationInfo = ( return { message: strings.appealDateNotBegun, date: null } } - // TODO: Move to the server as today may not be accurate in the client - const today = new Date() const expiryDate = new Date(verdictAppealDeadline) - const message = - today < expiryDate - ? strings.appealExpirationDate - : strings.appealDateExpired + const message = isVerdictAppealDeadlineExpired + ? strings.appealDateExpired + : strings.appealExpirationDate return { message, date: formatDate(expiryDate) } } @@ -72,6 +70,7 @@ export const DefendantInfo: FC = (props) => { const appealExpirationInfo = getAppealExpirationInfo( defendant.verdictAppealDeadline, + defendant.isVerdictAppealDeadlineExpired, defendant.serviceRequirement, )