Skip to content

Commit

Permalink
feat(j-s): Data structure for civil claimants (#16059)
Browse files Browse the repository at this point in the history
* Add CivilClaimants table

* Fix GQL

* Remove unused code

* Fix unreachable code error

* Align nullability between typescript and GQL fields. Field: created

* Add modified field to create civil claimant migration

* Better types

* Revert better types

* Remove unused imports

* Fix imports

* Fix imports

* Fix imports

* Fix imports

* remove everything but caseid from create civil claimant

* fix(j-s): remove civil claim ordering from case list

---------

Co-authored-by: unakb <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent 5d3444a commit 1cd87ee
Show file tree
Hide file tree
Showing 27 changed files with 782 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
SignatureConfirmationResponse,
} from '../case'
import { CaseListEntry } from '../case-list'
import { Defendant, DeleteDefendantResponse } from '../defendant'
import {
CivilClaimant,
Defendant,
DeleteCivilClaimantResponse,
DeleteDefendantResponse,
} from '../defendant'
import { CreateEventLogInput } from '../event-log'
import {
CaseFile,
Expand Down Expand Up @@ -329,6 +334,31 @@ export class BackendService extends DataSource<{ req: Request }> {
return this.delete(`case/${caseId}/defendant/${defendantId}`)
}

createCivilClaimant(
caseId: string,
createCivilClaimant: unknown,
): Promise<CivilClaimant> {
return this.post(`case/${caseId}/civilClaimant`, createCivilClaimant)
}

updateCivilClaimant(
caseId: string,
civilClaimantId: string,
updateCivilClaimant: unknown,
): Promise<CivilClaimant> {
return this.patch(
`case/${caseId}/civilClaimant/${civilClaimantId}`,
updateCivilClaimant,
)
}

deleteCivilClaimant(
caseId: string,
civilClaimantId: string,
): Promise<DeleteCivilClaimantResponse> {
return this.delete(`case/${caseId}/civilClaimant/${civilClaimantId}`)
}

createIndictmentCount(
input: CreateIndictmentCountInput,
): Promise<IndictmentCount> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,9 @@ export class UpdateCaseInput {
@IsOptional()
@Field(() => String, { nullable: true })
readonly civilDemands?: string

@Allow()
@IsOptional()
@Field(() => Boolean, { nullable: true })
readonly hasCivilClaims?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
UserRole,
} from '@island.is/judicial-system/types'

import { Defendant } from '../../defendant'
import { CivilClaimant, Defendant } from '../../defendant'
import { EventLog } from '../../event-log'
import { CaseFile } from '../../file'
import { IndictmentCount } from '../../indictment-count'
Expand Down Expand Up @@ -454,6 +454,12 @@ export class Case {
@Field(() => [Case], { nullable: true })
readonly mergedCases?: Case[]

@Field(() => [CivilClaimant], { nullable: true })
readonly civilClaimants?: CivilClaimant[]

@Field(() => String, { nullable: true })
readonly civilDemands?: string

@Field(() => Boolean, { nullable: true })
readonly hasCivilClaims?: boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Inject, Logger, UseGuards } from '@nestjs/common'
import { Args, Context, Mutation, Resolver } from '@nestjs/graphql'

import { LOGGER_PROVIDER } from '@island.is/logging'

import {
AuditedAction,
AuditTrailService,
} from '@island.is/judicial-system/audit-trail'
import {
CurrentGraphQlUser,
JwtGraphQlAuthGuard,
} from '@island.is/judicial-system/auth'
import type { User } from '@island.is/judicial-system/types'

import { BackendService } from '../backend'
import { CreateCivilClaimantInput } from './dto/createCivilClaimant.input'
import { DeleteCivilClaimantInput } from './dto/deleteCivilClaimant.input'
import { UpdateCivilClaimantInput } from './dto/updateCivilClaimant.input'
import { CivilClaimant } from './models/civilClaimant.model'
import { DeleteCivilClaimantResponse } from './models/deleteCivilClaimant.response'

@UseGuards(JwtGraphQlAuthGuard)
@Resolver(() => CivilClaimant)
export class CivilClaimantResolver {
constructor(
private readonly auditTrailService: AuditTrailService,
@Inject(LOGGER_PROVIDER)
private readonly logger: Logger,
) {}

@Mutation(() => CivilClaimant)
createCivilClaimant(
@Args('input', { type: () => CreateCivilClaimantInput })
input: CreateCivilClaimantInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<CivilClaimant> {
const { caseId, ...createCivilClaimant } = input

return this.auditTrailService.audit(
user.id,
AuditedAction.CREATE_CIVIL_CLAIMANT,
backendService.createCivilClaimant(caseId, createCivilClaimant),
(civilClaimant) => civilClaimant.id,
)
}

@Mutation(() => CivilClaimant)
updateCivilClaimant(
@Args('input', { type: () => UpdateCivilClaimantInput })
input: UpdateCivilClaimantInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<CivilClaimant> {
const { caseId, civilClaimantId, ...updateCivilClaimant } = input

return this.auditTrailService.audit(
user.id,
AuditedAction.UPDATE_CIVIL_CLAIMANT,
backendService.updateCivilClaimant(
caseId,
civilClaimantId,
updateCivilClaimant,
),
(civilClaimant) => civilClaimant.id,
)
}

@Mutation(() => DeleteCivilClaimantResponse)
async deleteCivilClaimant(
@Args('input', { type: () => DeleteCivilClaimantInput })
input: DeleteCivilClaimantInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<DeleteCivilClaimantResponse> {
const { caseId, civilClaimantId } = input

return this.auditTrailService.audit(
user.id,
AuditedAction.DELETE_CIVIL_CLAIMANT,
backendService.deleteCivilClaimant(caseId, civilClaimantId),
civilClaimantId,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Module } from '@nestjs/common'

import { CivilClaimantResolver } from './civilClaimant.resolver'
import { DefendantResolver } from './defendant.resolver'

@Module({
providers: [DefendantResolver],
providers: [DefendantResolver, CivilClaimantResolver],
})
export class DefendantModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Allow } from 'class-validator'

import { Field, ID, InputType } from '@nestjs/graphql'

@InputType()
export class CreateCivilClaimantInput {
@Allow()
@Field(() => ID)
readonly caseId!: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Allow } from 'class-validator'

import { Field, ID, InputType } from '@nestjs/graphql'

@InputType()
export class DeleteCivilClaimantInput {
@Allow()
@Field(() => ID)
readonly caseId!: string

@Allow()
@Field(() => ID)
readonly civilClaimantId!: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Allow, IsOptional } from 'class-validator'

import { Field, ID, InputType } from '@nestjs/graphql'

@InputType()
export class UpdateCivilClaimantInput {
@Allow()
@Field(() => ID)
readonly civilClaimantId!: string

@Allow()
@Field(() => ID)
readonly caseId!: string

@Allow()
@IsOptional()
@Field(() => Boolean, { nullable: true })
readonly noNationalId?: boolean

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly name?: string

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly nationalId?: string

@Allow()
@IsOptional()
@Field(() => Boolean, { nullable: true })
readonly hasSpokesperson?: boolean

@Allow()
@IsOptional()
@Field(() => Boolean, { nullable: true })
readonly spokespersonIsLawyer?: boolean

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly spokespersonNationalId?: string

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly spokespersonName?: string

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly spokespersonEmail?: string

@Allow()
@IsOptional()
@Field(() => String, { nullable: true })
readonly spokespersonPhoneNumber?: string

@Allow()
@IsOptional()
@Field(() => Boolean, { nullable: true })
readonly caseFilesSharedWithSpokesperson?: boolean
}
2 changes: 2 additions & 0 deletions apps/judicial-system/api/src/app/modules/defendant/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { Defendant } from './models/defendant.model'
export { DeleteDefendantResponse } from './models/delete.response'
export { CivilClaimant } from './models/civilClaimant.model'
export { DeleteCivilClaimantResponse } from './models/deleteCivilClaimant.response'
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Field, ID, ObjectType } from '@nestjs/graphql'

@ObjectType()
export class CivilClaimant {
@Field(() => ID)
readonly id!: string

@Field(() => String, { nullable: true })
readonly created?: string

@Field(() => String, { nullable: true })
readonly modified?: string

@Field(() => ID, { nullable: true })
readonly caseId!: string

@Field(() => Boolean, { nullable: true })
readonly noNationalId?: boolean

@Field(() => String, { nullable: true })
readonly name?: string

@Field(() => String, { nullable: true })
readonly nationalId?: string

@Field(() => Boolean, { nullable: true })
readonly hasSpokesperson?: boolean

@Field(() => Boolean, { nullable: true })
readonly spokespersonIsLawyer?: boolean

@Field(() => String, { nullable: true })
readonly spokespersonNationalId?: string

@Field(() => String, { nullable: true })
readonly spokespersonName?: string

@Field(() => String, { nullable: true })
readonly spokespersonEmail?: string

@Field(() => String, { nullable: true })
readonly spokespersonPhoneNumber?: string

@Field(() => Boolean, { nullable: true })
readonly caseFilesSharedWithSpokesperson?: boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Field, ObjectType } from '@nestjs/graphql'

@ObjectType()
export class DeleteCivilClaimantResponse {
@Field(() => Boolean)
deleted!: boolean
}
Loading

0 comments on commit 1cd87ee

Please sign in to comment.