Skip to content

Commit

Permalink
Merge branch 'fix/signature-collection-active' of github.com:island-i…
Browse files Browse the repository at this point in the history
…s/island.is into fix/signature-collection-active
  • Loading branch information
juni-haukur committed Sep 30, 2024
2 parents 96ef52c + d265ca1 commit 9b941b5
Show file tree
Hide file tree
Showing 124 changed files with 3,714 additions and 491 deletions.
46 changes: 39 additions & 7 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,15 +1146,29 @@ export class CaseService {
private addMessagesForNewCourtDateToQueue(
theCase: Case,
user: TUser,
arraignmentDateChanged: boolean,
): Promise<void> {
return this.messageService.sendMessagesToQueue([
const messages: Message[] = [
{
type: MessageType.NOTIFICATION,
user,
caseId: theCase.id,
body: { type: NotificationType.COURT_DATE },
},
])
]

if (arraignmentDateChanged) {
theCase.defendants?.forEach((defendant) => {
messages.push({
type: MessageType.DELIVERY_TO_POLICE_SUBPOENA,
user,
caseId: theCase.id,
elementId: defendant.id,
})
})
}

return this.messageService.sendMessagesToQueue(messages)
}

private async addMessagesForUpdatedCaseToQueue(
Expand Down Expand Up @@ -1313,11 +1327,29 @@ export class CaseService {
}

// This only applies to indictments
const courtDate = DateLog.courtDate(theCase.dateLogs)
const updatedCourtDate = DateLog.courtDate(updatedCase.dateLogs)
if (updatedCourtDate && updatedCourtDate.date !== courtDate?.date) {
// New court date
await this.addMessagesForNewCourtDateToQueue(updatedCase, user)
if (isIndictment) {
const arraignmentDate = DateLog.arraignmentDate(theCase.dateLogs)
const updatedArraignmentDate = DateLog.arraignmentDate(
updatedCase.dateLogs,
)
const arraignmentDateChanged =
updatedArraignmentDate &&
updatedArraignmentDate.date.getTime() !==
arraignmentDate?.date.getTime()
const courtDate = DateLog.courtDate(theCase.dateLogs)
const updatedCourtDate = DateLog.courtDate(updatedCase.dateLogs)
const courtDateChanged =
updatedCourtDate &&
updatedCourtDate.date.getTime() !== courtDate?.date.getTime()

if (arraignmentDateChanged || courtDateChanged) {
// New arraignment date or new court date
await this.addMessagesForNewCourtDateToQueue(
updatedCase,
user,
Boolean(arraignmentDateChanged),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,56 @@ describe('CaseController - Update', () => {
})
})

describe('court date updated', () => {
describe('indictment arraignment date updated', () => {
const arraignmentDate = { date: new Date(), location: uuid() }
const caseToUpdate = { arraignmentDate }
const updatedCase = {
...theCase,
type: CaseType.INDICTMENT,
dateLogs: [{ dateType: DateType.ARRAIGNMENT_DATE, ...arraignmentDate }],
}

beforeEach(async () => {
const mockFindOne = mockCaseModel.findOne as jest.Mock
mockFindOne.mockResolvedValueOnce(updatedCase)

await givenWhenThen(caseId, user, theCase, caseToUpdate)
})

it('should update case', () => {
expect(mockDateLogModel.create).toHaveBeenCalledWith(
{ dateType: DateType.ARRAIGNMENT_DATE, caseId, ...arraignmentDate },
{ transaction },
)
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([
{
type: MessageType.NOTIFICATION,
user,
caseId,
body: { type: NotificationType.COURT_DATE },
},
{
type: MessageType.DELIVERY_TO_POLICE_SUBPOENA,
user,
caseId: theCase.id,
elementId: defendantId1,
},
{
type: MessageType.DELIVERY_TO_POLICE_SUBPOENA,
user,
caseId: theCase.id,
elementId: defendantId2,
},
])
})
})

describe('indictment court date updated', () => {
const courtDate = { date: new Date(), location: uuid() }
const caseToUpdate = { courtDate }
const updatedCase = {
...theCase,
type: CaseType.INDICTMENT,
dateLogs: [{ dateType: DateType.COURT_DATE, ...courtDate }],
}

Expand All @@ -892,7 +937,6 @@ describe('CaseController - Update', () => {
{ dateType: DateType.COURT_DATE, caseId, ...courtDate },
{ transaction },
)

expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([
{
type: MessageType.NOTIFICATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ export class NotificationService {
]
} else {
messages = [this.getNotificationMessage(type, user, theCase)]
theCase.defendants?.forEach((defendant) => {
// TODO: move this elsewhere when we know exactly where the trigger should be
messages.push({
type: MessageType.DELIVERY_TO_POLICE_SUBPOENA,
user,
caseId: theCase.id,
elementId: defendant.id,
})
})
}
break
case NotificationType.HEADS_UP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class SubpoenaService {
return { delivered: false }
}

// TODO: Improve error handling by checking how many rows were affected and posting error event
await this.subpoenaModel.update(
{ subpoenaId: createdSubpoena.subpoenaId },
{ where: { id: subpoena.id } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ import {
SectionHeading,
useCourtArrangements,
} from '@island.is/judicial-system-web/src/components'
import { NotificationType } from '@island.is/judicial-system-web/src/graphql/schema'
import { SubpoenaType } from '@island.is/judicial-system-web/src/routes/Court/components'
import type { stepValidationsType } from '@island.is/judicial-system-web/src/utils/formHelper'
import {
useCase,
useDefendants,
} from '@island.is/judicial-system-web/src/utils/hooks'
import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/stepHelper'
import { useDefendants } from '@island.is/judicial-system-web/src/utils/hooks'
import { isSubpoenaStepValid } from '@island.is/judicial-system-web/src/utils/validate'

import { subpoena as strings } from './Subpoena.strings'
Expand All @@ -39,12 +34,10 @@ const Subpoena: FC = () => {
const { formatMessage } = useIntl()
const {
courtDate,
courtDateHasChanged,
handleCourtDateChange,
handleCourtRoomChange,
sendCourtDateToServer,
} = useCourtArrangements(workingCase, setWorkingCase, 'arraignmentDate')
const { sendNotification } = useCase()

const isArraignmentScheduled = Boolean(workingCase.arraignmentDate)

Expand All @@ -69,18 +62,6 @@ const Subpoena: FC = () => {
})
}

if (
!hasSentNotification(
NotificationType.COURT_DATE,
workingCase.notifications,
).hasSent ||
courtDateHasChanged
) {
promises.push(
sendNotification(workingCase.id, NotificationType.COURT_DATE),
)
}

const allDataSentToServer = await Promise.all(promises)
if (!allDataSentToServer.every((result) => result)) {
return
Expand All @@ -92,11 +73,8 @@ const Subpoena: FC = () => {
isArraignmentScheduled,
sendCourtDateToServer,
workingCase.defendants,
workingCase.notifications,
workingCase.id,
courtDateHasChanged,
updateDefendant,
sendNotification,
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ const Processing: FC = () => {
civilClaimantNationalIdUpdate?.nationalId,
)

const stepIsValid =
isProcessingStepValidIndictments(workingCase) &&
nationalIdNotFound === false
const stepIsValid = isProcessingStepValidIndictments(workingCase)

const handleUpdateDefendant = useCallback(
(updatedDefendant: UpdateDefendantInput) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ export const ApplicationsPreview = ({
/>
}
progress={
type !== 'incomplete'
? undefined
: application.actionCard?.draftFinishedSteps ?? 0
type === 'incomplete'
? application.actionCard?.draftFinishedSteps ?? 0
: undefined
}
progressTotalSteps={
type === 'incomplete'
? application.actionCard?.draftTotalSteps ?? 0
: undefined
}
progressTotalSteps={application.actionCard?.draftTotalSteps ?? 0}
progressMessage={intl.formatMessage(
{
id: 'applicationStatusCard.draftProgress',
Expand Down
2 changes: 1 addition & 1 deletion apps/services/auth/admin-api/infra/auth-admin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const serviceSetup = (): ServiceBuilder<'services-auth-admin-api'> => {
SYSLUMENN_HOST: {
dev: 'https://api.syslumenn.is/staging',
staging: 'https://api.syslumenn.is/staging',
prod: 'https://api.syslumenn.is',
prod: 'https://api.syslumenn.is/api',
},
SYSLUMENN_TIMEOUT: '3000',
ZENDESK_CONTACT_FORM_SUBDOMAIN: {
Expand Down
2 changes: 1 addition & 1 deletion apps/services/auth/delegation-api/infra/delegation-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const serviceSetup = (services: {
SYSLUMENN_HOST: {
dev: 'https://api.syslumenn.is/staging',
staging: 'https://api.syslumenn.is/staging',
prod: 'https://api.syslumenn.is',
prod: 'https://api.syslumenn.is/api',
},
SYSLUMENN_TIMEOUT: '3000',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ export class DelegationIndexController {
...parsedDelegationInfo,
},
},
this.delegationIndexService.createOrUpdateDelegationRecord({
...parsedDelegationInfo,
provider: auth.delegationProvider,
validTo: body.validTo,
}),
this.delegationIndexService.createOrUpdateDelegationRecord(
{
...parsedDelegationInfo,
provider: auth.delegationProvider,
validTo: body.validTo,
},
auth,
),
)
}

Expand Down Expand Up @@ -126,10 +129,13 @@ export class DelegationIndexController {
...parsedDelegationInfo,
},
},
this.delegationIndexService.removeDelegationRecord({
...parsedDelegationInfo,
provider: auth.delegationProvider,
}),
this.delegationIndexService.removeDelegationRecord(
{
...parsedDelegationInfo,
provider: auth.delegationProvider,
},
auth,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ describe('DelegationsIndexService', () => {
const nationalId = user.nationalId

// Act
await delegationIndexService.indexCustomDelegations(nationalId)
await delegationIndexService.indexCustomDelegations(nationalId, user)

// Assert
const delegations = await delegationIndexModel.findAll({
Expand Down Expand Up @@ -480,7 +480,10 @@ describe('DelegationsIndexService', () => {
const nationalId = user.nationalId

// Act
await delegationIndexService.indexRepresentativeDelegations(nationalId)
await delegationIndexService.indexRepresentativeDelegations(
nationalId,
user,
)

// Assert
const delegations = await delegationIndexModel.findAll({
Expand Down Expand Up @@ -625,7 +628,7 @@ describe('DelegationsIndexService', () => {
const nationalId = user.nationalId

// Act
await delegationIndexService.indexCustomDelegations(nationalId)
await delegationIndexService.indexCustomDelegations(nationalId, user)

// Assert
const delegations = await delegationModel.findAll({
Expand Down
2 changes: 1 addition & 1 deletion apps/services/auth/ids-api/infra/ids-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const serviceSetup = (): ServiceBuilder<'services-auth-ids-api'> => {
SYSLUMENN_HOST: {
dev: 'https://api.syslumenn.is/staging',
staging: 'https://api.syslumenn.is/staging',
prod: 'https://api.syslumenn.is',
prod: 'https://api.syslumenn.is/api',
},
SYSLUMENN_TIMEOUT: '3000',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const serviceSetup =
SYSLUMENN_HOST: {
dev: 'https://api.syslumenn.is/staging',
staging: 'https://api.syslumenn.is/staging',
prod: 'https://api.syslumenn.is',
prod: 'https://api.syslumenn.is/api',
},
SYSLUMENN_TIMEOUT: '3000',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class PersonalRepresentativesController {

return personalRepresentative
}

/** Removes a personal representative by its id */
@Delete(':id')
@Documentation({
Expand Down Expand Up @@ -135,6 +136,7 @@ export class PersonalRepresentativesController {
// Index personal representative delegations for the personal representative
void this.delegationIndexService.indexRepresentativeDelegations(
deletedPersonalRepresentative.nationalIdPersonalRepresentative,
user,
)
}
}
Expand Down Expand Up @@ -203,6 +205,7 @@ export class PersonalRepresentativesController {
// Index personal representative delegations for the personal representative
void this.delegationIndexService.indexRepresentativeDelegations(
createdPersonalRepresentative.nationalIdPersonalRepresentative,
user,
)
}

Expand Down
2 changes: 1 addition & 1 deletion apps/services/auth/public-api/infra/auth-public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const serviceSetup = (): ServiceBuilder<'services-auth-public-api'> => {
SYSLUMENN_HOST: {
dev: 'https://api.syslumenn.is/staging',
staging: 'https://api.syslumenn.is/staging',
prod: 'https://api.syslumenn.is',
prod: 'https://api.syslumenn.is/api',
},
SYSLUMENN_TIMEOUT: '3000',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const AccordionSlice: React.FC<React.PropsWithChildren<SliceProps>> = ({
))}
{slice.type === 'accordion_minimal' && (
<Box paddingTop={4}>
<Accordion>
<Accordion singleExpand={false}>
{(slice.accordionItems ?? []).map((item) => (
<AccordionItem
key={item.id}
Expand Down
Loading

0 comments on commit 9b941b5

Please sign in to comment.