Skip to content

Commit

Permalink
Merge branch 'main' into j-s/fix-service-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
unakb authored Oct 24, 2024
2 parents b520e94 + 66f2b3b commit cab3b6b
Show file tree
Hide file tree
Showing 42 changed files with 694 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Defendant } from '../../defendant'
import { Case } from '../models/case.model'
import {
getAppealInfo,
getDefendantsInfo,
getIndictmentDefendantsInfo,
getIndictmentInfo,
transformCase,
} from './case.transformer'
Expand Down Expand Up @@ -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,
},
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,24 @@ 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
? new Date(
new Date(verdictViewDate).getTime() + getDays(28),
).toISOString()
: undefined
const isVerdictAppealDeadlineExpired = verdictAppealDeadline
? Date.now() >= new Date(verdictAppealDeadline).getTime()
: false

return {
...defendant,
verdictAppealDeadline,
isVerdictAppealDeadlineExpired,
}
})
}
Expand All @@ -194,7 +200,7 @@ const transformIndictmentCase = (theCase: Case): Case => {
theCase.defendants,
theCase.eventLogs,
),
defendants: getDefendantsInfo(theCase.defendants),
defendants: getIndictmentDefendantsInfo(theCase.defendants),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down Expand Up @@ -39,11 +44,34 @@ export const canDefenderViewRequest = (theCase: Case) => {
)
}

export const transformLimitedAccessCase = (theCase: Case): Case => {
const transformRequestCase = (theCase: Case): Case => {
return {
...theCase,
caseResentExplanation: canDefenderViewRequest(theCase)
? theCase.caseResentExplanation
: 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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ query Case($input: CaseQueryInput!) {
serviceRequirement
verdictViewDate
verdictAppealDeadline
isVerdictAppealDeadlineExpired
subpoenaType
subpoenas {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ query LimitedAccessCase($input: CaseQueryInput!) {
defenderEmail
defenderPhoneNumber
defenderChoice
serviceRequirement
verdictViewDate
verdictAppealDeadline
isVerdictAppealDeadlineExpired
subpoenas {
id
created
Expand Down Expand Up @@ -166,6 +168,8 @@ query LimitedAccessCase($input: CaseQueryInput!) {
indictmentRulingDecision
indictmentCompletedDate
indictmentReviewDecision
indictmentVerdictViewedByAll
indictmentVerdictAppealDeadlineExpired
indictmentReviewer {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface DefendantInfoProps {

export const getAppealExpirationInfo = (
verdictAppealDeadline?: string | null,
isVerdictAppealDeadlineExpired?: boolean | null,
serviceRequirement?: ServiceRequirement | null,
) => {
if (serviceRequirement === ServiceRequirement.NOT_REQUIRED) {
Expand All @@ -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) }
}
Expand All @@ -72,6 +70,7 @@ export const DefendantInfo: FC<DefendantInfoProps> = (props) => {

const appealExpirationInfo = getAppealExpirationInfo(
defendant.verdictAppealDeadline,
defendant.isVerdictAppealDeadlineExpired,
defendant.serviceRequirement,
)

Expand Down
Loading

0 comments on commit cab3b6b

Please sign in to comment.