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

chore(j-s): add a function to get indictment deadline date #17583

Merged
merged 24 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b66d6f2
chore(j-s): add a function to get indictment deadline date
thorhildurt Jan 21, 2025
8eeecd4
fix(j-s): small fix
thorhildurt Jan 21, 2025
27946d7
chore(j-s): refactor current logic to use the new function
thorhildurt Jan 21, 2025
bb47ea5
fix(j-s): remove unused function
thorhildurt Jan 21, 2025
cac9f57
fix(j-s): rename
thorhildurt Jan 21, 2025
ec0dbbf
fix(j-s): rename and add different func for appeal date
thorhildurt Jan 21, 2025
1c67458
fix(j-s): add test for appeal deadline date
thorhildurt Jan 21, 2025
91397b4
chore: nx format:write update dirty files
andes-it Jan 21, 2025
f1afa5a
fix(j-s): add description for different appeal props
thorhildurt Jan 21, 2025
0e2fa85
fix(j-s): formatting and tiny adjustments
thorhildurt Jan 21, 2025
2d1a460
Merge branch 'j-s/fixAppealDeadline' of https://github.com/island-is/…
thorhildurt Jan 21, 2025
862a0d6
fix(j-s): add test for hasDatePassed
thorhildurt Jan 21, 2025
5400d6b
Merge branch 'main' of https://github.com/island-is/island.is into j-…
thorhildurt Jan 21, 2025
245ffed
fix(j-s): format
thorhildurt Jan 21, 2025
c193073
fix(j-s): tests
thorhildurt Jan 21, 2025
9777093
fix(j-s): format
thorhildurt Jan 21, 2025
3b0f0f9
fix(j-s): revert updates to appeal deadline date
thorhildurt Jan 22, 2025
9d24f7d
fix(j-s): small fix
thorhildurt Jan 22, 2025
020b658
chore: nx format:write update dirty files
andes-it Jan 22, 2025
bee910a
fix(j-s): small feedback fixes
thorhildurt Jan 24, 2025
15a34e4
Merge branch 'main' of https://github.com/island-is/island.is into j-…
thorhildurt Jan 24, 2025
addc331
fix(j-s): use endOfDay from date-fns
thorhildurt Jan 24, 2025
701b4a2
Merge branch 'j-s/fixAppealDeadline' of https://github.com/island-is/…
thorhildurt Jan 24, 2025
69d5831
chore: nx format:write update dirty files
andes-it Jan 24, 2025
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,8 +540,8 @@ describe('getAppealInfo', () => {
expect(appealInfo).toEqual({})
})

it('should return not return appealedDate if case has not been appealed', () => {
const rulingDate = new Date().toISOString()
it('should not return appealedDate if case has not been appealed', () => {
const rulingDate = '2022-06-15T19:50:08.033Z'
const theCase = {
type: CaseType.CUSTODY,
rulingDate,
Expand All @@ -557,16 +557,14 @@ describe('getAppealInfo', () => {
expect(appealInfo).toEqual({
canBeAppealed: true,
hasBeenAppealed: false,
appealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3),
).toISOString(),
appealDeadline: '2022-06-18T19:50:08.033Z',
oddsson marked this conversation as resolved.
Show resolved Hide resolved
canDefenderAppeal: true,
canProsecutorAppeal: true,
})
})

it('should return correct appeal info when ruling date is provided', () => {
const rulingDate = new Date().toISOString()
const rulingDate = '2022-06-15T19:50:08.033Z'
const theCase = {
type: CaseType.CUSTODY,
rulingDate,
Expand All @@ -584,9 +582,7 @@ describe('getAppealInfo', () => {
hasBeenAppealed: true,
appealedByRole: UserRole.DEFENDER,
appealedDate: '2022-06-15T19:50:08.033Z',
appealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3),
).toISOString(),
appealDeadline: '2022-06-18T19:50:08.033Z',
statementDeadline: '2021-06-16T19:50:08.033Z',
canDefenderAppeal: false,
canProsecutorAppeal: false,
Expand Down Expand Up @@ -669,26 +665,24 @@ describe('getIndictmentInfo', () => {
})

it('should return correct indictment info when ruling date is provided', () => {
const rulingDate = new Date().toISOString()
const rulingDate = '2022-06-15T19:50:08.033Z'

const indictmentInfo = getIndictmentInfo(
CaseIndictmentRulingDecision.RULING,
rulingDate,
)

expect(indictmentInfo).toEqual({
indictmentAppealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 28),
).toISOString(),
indictmentAppealDeadline: '2022-07-13T23:59:59.999Z',
indictmentVerdictViewedByAll: true,
indictmentVerdictAppealDeadlineExpired: true,
})
})

it('should return correct indictment info when some defendants have yet to view the verdict', () => {
const rulingDate = new Date().toISOString()
const rulingDate = '2022-06-14T19:50:08.033Z'
const defendants = [
{ verdictViewDate: new Date().toISOString() } as Defendant,
{ verdictViewDate: '2022-06-15T19:50:08.033Z' } as Defendant,
{ verdictViewDate: undefined } as Defendant,
]

Expand All @@ -699,18 +693,16 @@ describe('getIndictmentInfo', () => {
)

expect(indictmentInfo).toEqual({
indictmentAppealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 28),
).toISOString(),
indictmentAppealDeadline: '2022-07-12T23:59:59.999Z',
indictmentVerdictViewedByAll: false,
indictmentVerdictAppealDeadlineExpired: false,
})
})

it('should return correct indictment info when no defendants have yet to view the verdict', () => {
const rulingDate = new Date().toISOString()
const rulingDate = '2022-06-14T19:50:08.033Z'
const defendants = [
{ verdictViewDate: new Date().toISOString() } as Defendant,
{ verdictViewDate: '2022-06-15T19:50:08.033Z' } as Defendant,
{
serviceRequirement: ServiceRequirement.NOT_REQUIRED,
verdictViewDate: undefined,
Expand All @@ -724,16 +716,14 @@ describe('getIndictmentInfo', () => {
)

expect(indictmentInfo).toEqual({
indictmentAppealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 28),
).toISOString(),
indictmentAppealDeadline: '2022-07-12T23:59:59.999Z',
indictmentVerdictViewedByAll: true,
indictmentVerdictAppealDeadlineExpired: false,
})
})

it('should return correct indictment info when the indictment ruling decision is FINE and the appeal deadline is not expired', () => {
const rulingDate = new Date().toISOString()
const rulingDate = new Date()
const defendants = [
{
serviceRequirement: ServiceRequirement.NOT_REQUIRED,
Expand All @@ -743,14 +733,21 @@ describe('getIndictmentInfo', () => {

const indictmentInfo = getIndictmentInfo(
CaseIndictmentRulingDecision.FINE,
rulingDate,
rulingDate.toISOString(),
defendants,
)

const expectedIndictmentAppealDeadline = new Date(
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
rulingDate.getFullYear(),
rulingDate.getMonth(),
rulingDate.getDate() + 3,
23,
59,
59,
999,
)
expect(indictmentInfo).toEqual({
indictmentAppealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3),
).toISOString(),
indictmentAppealDeadline: expectedIndictmentAppealDeadline.toISOString(),
indictmentVerdictViewedByAll: true,
indictmentVerdictAppealDeadlineExpired: false,
})
Expand All @@ -772,9 +769,7 @@ describe('getIndictmentInfo', () => {
)

expect(indictmentInfo).toEqual({
indictmentAppealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3),
).toISOString(),
indictmentAppealDeadline: '2024-05-29T23:59:59.999Z',
indictmentVerdictViewedByAll: true,
indictmentVerdictAppealDeadlineExpired: true,
})
Expand All @@ -801,7 +796,7 @@ describe('getIndictmentDefendantsInfo', () => {
{
verdictViewDate: '2022-06-15T19:50:08.033Z',
serviceRequirement: ServiceRequirement.REQUIRED,
verdictAppealDeadline: '2022-07-13T19:50:08.033Z',
verdictAppealDeadline: '2022-07-13T23:59:59.999Z',
isVerdictAppealDeadlineExpired: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import {
getAppealDeadlineDate,
getIndictmentAppealDeadlineDate,
hasDatePassed,
} from '@island.is/judicial-system/types'
import {
CaseAppealDecision,
CaseIndictmentRulingDecision,
EventType,
FINE_APPEAL_WINDOW_DAYS,
getIndictmentVerdictAppealDeadlineStatus,
getStatementDeadline,
isRequestCase,
ServiceRequirement,
UserRole,
VERDICT_APPEAL_WINDOW_DAYS,
} from '@island.is/judicial-system/types'

import { Defendant } from '../../defendant'
Expand Down Expand Up @@ -93,9 +96,9 @@ export const getAppealInfo = (theCase: Case): AppealInfo => {
)

const theRulingDate = new Date(rulingDate)
appealInfo.appealDeadline = new Date(
theRulingDate.getTime() + getDays(3),
).toISOString()
appealInfo.appealDeadline = getAppealDeadlineDate({
baseDate: theRulingDate,
}).toISOString()

appealInfo.canProsecutorAppeal =
!hasBeenAppealed && isAppealableDecision(prosecutorAppealDecision)
Expand All @@ -121,7 +124,7 @@ const transformRequestCase = (theCase: Case): Case => {
isClosedCourtHidden: theCase.isClosedCourtHidden ?? false,
isHeightenedSecurityLevel: theCase.isHeightenedSecurityLevel ?? false,
isValidToDateInThePast: theCase.validToDate
? Date.now() > new Date(theCase.validToDate).getTime()
? hasDatePassed(new Date(theCase.validToDate))
: theCase.isValidToDateInThePast,

// TODO: Move remaining appeal fields to appealInfo
Expand Down Expand Up @@ -151,19 +154,18 @@ export const getIndictmentInfo = (
defendants?: Defendant[],
eventLog?: EventLog[],
): IndictmentInfo => {
const indictmentInfo: IndictmentInfo = {}
const isFine = rulingDecision === CaseIndictmentRulingDecision.FINE
const isRuling = rulingDecision === CaseIndictmentRulingDecision.RULING

if (!rulingDate) {
return indictmentInfo
return {}
}

const theRulingDate = new Date(rulingDate)
indictmentInfo.indictmentAppealDeadline = new Date(
theRulingDate.getTime() +
getDays(isFine ? FINE_APPEAL_WINDOW_DAYS : VERDICT_APPEAL_WINDOW_DAYS),
).toISOString()
const indictmentAppealDeadline = getIndictmentAppealDeadlineDate({
baseDate: theRulingDate,
isFine,
}).toISOString()

const verdictInfo = defendants?.map<[boolean, Date | undefined]>(
(defendant) => [
Expand All @@ -180,15 +182,17 @@ export const getIndictmentInfo = (

const [indictmentVerdictViewedByAll, indictmentVerdictAppealDeadlineExpired] =
getIndictmentVerdictAppealDeadlineStatus(verdictInfo, isFine)
indictmentInfo.indictmentVerdictViewedByAll = indictmentVerdictViewedByAll
indictmentInfo.indictmentVerdictAppealDeadlineExpired =
indictmentVerdictAppealDeadlineExpired

indictmentInfo.indictmentCompletedDate = eventLog
const indictmentCompletedDate = eventLog
?.find((log) => log.eventType === EventType.INDICTMENT_COMPLETED)
?.created?.toString()

return indictmentInfo
return {
indictmentAppealDeadline,
indictmentVerdictViewedByAll,
indictmentVerdictAppealDeadlineExpired,
indictmentCompletedDate,
}
}

export const getIndictmentDefendantsInfo = (theCase: Case) => {
Expand All @@ -201,23 +205,18 @@ export const getIndictmentDefendantsInfo = (theCase: Case) => {
const { verdictViewDate } = defendant

const baseDate = serviceRequired ? verdictViewDate : theCase.rulingDate

const verdictAppealDeadline = baseDate
? new Date(
new Date(baseDate).getTime() +
getDays(
isFine ? FINE_APPEAL_WINDOW_DAYS : VERDICT_APPEAL_WINDOW_DAYS,
),
).toISOString()
? getIndictmentAppealDeadlineDate({
baseDate: new Date(baseDate),
isFine,
})
: undefined

const isVerdictAppealDeadlineExpired = verdictAppealDeadline
? Date.now() >= new Date(verdictAppealDeadline).getTime()
: false
const isVerdictAppealDeadlineExpired =
!!verdictAppealDeadline && hasDatePassed(verdictAppealDeadline)

return {
...defendant,
verdictAppealDeadline,
verdictAppealDeadline: verdictAppealDeadline?.toISOString(),
isVerdictAppealDeadlineExpired,
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ export class Case {
@Field(() => Boolean, { nullable: true })
readonly hasBeenAppealed?: boolean

@Field(() => String, { nullable: true })
@Field(() => String, {
nullable: true,
description: 'appeal deadline in R cases',
})
readonly appealDeadline?: string

@Field(() => UserRole, { nullable: true })
Expand Down Expand Up @@ -430,7 +433,10 @@ export class Case {
@Field(() => IndictmentCaseReviewDecision, { nullable: true })
readonly indictmentReviewDecision?: IndictmentCaseReviewDecision

@Field(() => String, { nullable: true })
@Field(() => String, {
nullable: true,
description: 'appeal deadline for public prosecutor',
})
readonly indictmentAppealDeadline?: string

@Field(() => Boolean, { nullable: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FC, useContext, useMemo, useState } from 'react'
import { useIntl } from 'react-intl'
import addDays from 'date-fns/addDays'
import { AnimatePresence, motion } from 'framer-motion'
import { useRouter } from 'next/router'

Expand All @@ -14,7 +13,7 @@ import {
} from '@island.is/island-ui/core'
import { PUBLIC_PROSECUTOR_STAFF_INDICTMENT_SEND_TO_PRISON_ADMIN_ROUTE } from '@island.is/judicial-system/consts'
import { formatDate } from '@island.is/judicial-system/formatters'
import { VERDICT_APPEAL_WINDOW_DAYS } from '@island.is/judicial-system/types'
import { getIndictmentAppealDeadlineDate } from '@island.is/judicial-system/types'
import { core, errors } from '@island.is/judicial-system-web/messages'

import {
Expand Down Expand Up @@ -141,10 +140,10 @@ const BlueBoxWithDate: FC<Props> = (props) => {
const deadline =
defendant.verdictAppealDeadline ||
(dates.verdictViewDate &&
addDays(
dates.verdictViewDate,
VERDICT_APPEAL_WINDOW_DAYS,
).toISOString())
getIndictmentAppealDeadlineDate({
baseDate: dates.verdictViewDate,
isFine: false,
}).toISOString())
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved

return getAppealExpirationInfo(
deadline,
Expand Down
15 changes: 1 addition & 14 deletions apps/judicial-system/web/src/utils/utils.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import * as formatters from './formatters'
import { validateAndSendToServer } from './formHelper'
import { getAppealEndDate, getShortGender, hasSentNotification } from './utils'
import { getShortGender, hasSentNotification } from './utils'

describe('Utils', () => {
describe('removeTabs', () => {
Expand Down Expand Up @@ -93,19 +93,6 @@ describe('Utils', () => {
})
})

describe('getAppealEndDate', () => {
test('should return the correct end date', () => {
// Arrange
const date = '2020-10-24T12:25:00Z'

// Act
const result = getAppealEndDate(date)

// Assert
expect(result).toEqual('27. október 2020 kl. 12:25')
})
})

describe('getShortGender', () => {
test('should return short genders given a valid gender', () => {
// Arrange
Expand Down
8 changes: 0 additions & 8 deletions apps/judicial-system/web/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import addDays from 'date-fns/addDays'
import parseISO from 'date-fns/parseISO'

import { TagVariant } from '@island.is/island-ui/core'
import { formatDate } from '@island.is/judicial-system/formatters'
import {
Expand Down Expand Up @@ -60,11 +57,6 @@ export const fileSize = (bytes?: number) => {
return kb >= 10000 ? `${kb.toString().substring(0, 2)}MB` : `${kb}KB`
}

export const getAppealEndDate = (rulingDate: string) => {
const appealEndDate = addDays(parseISO(rulingDate), 3)
return formatDate(appealEndDate, 'PPPp')
}

export const isBusiness = (nationalId?: string | null) => {
if (!nationalId) {
return false
Expand Down
Loading
Loading