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

feat(j-s): Data structure for civil claimants #16059

Merged
merged 20 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -16,6 +16,8 @@ import {
} from '../case'
import { CaseListEntry } from '../case-list'
import { Defendant, DeleteDefendantResponse } from '../defendant'
import { CivilClaimant } from '../defendant/models/civilClaimant.model'
import { DeleteCivilClaimantResponse } from '../defendant/models/deleteCivilClaimant.response'
oddsson marked this conversation as resolved.
Show resolved Hide resolved
import { CreateEventLogInput } from '../event-log'
import {
CaseFile,
Expand Down Expand Up @@ -329,6 +331,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)
}
oddsson marked this conversation as resolved.
Show resolved Hide resolved

updateCivilClaimant(
caseId: string,
civilClaimantId: string,
updateCivilClaimant: unknown,
): Promise<CivilClaimant> {
return this.patch(
`case/${caseId}/civilClaimant/${civilClaimantId}`,
updateCivilClaimant,
)
}
oddsson marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -27,6 +27,7 @@ import {
} from '@island.is/judicial-system/types'

import { Defendant } from '../../defendant'
import { CivilClaimant } from '../../defendant/models/civilClaimant.model'
oddsson marked this conversation as resolved.
Show resolved Hide resolved
import { EventLog } from '../../event-log'
import { CaseFile } from '../../file'
import { IndictmentCount } from '../../indictment-count'
Expand Down Expand Up @@ -454,6 +455,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 {
oddsson marked this conversation as resolved.
Show resolved Hide resolved
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,60 @@
import { Allow, IsOptional } from 'class-validator'

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

@InputType()
export class CreateCivilClaimantInput {
@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
}
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
oddsson marked this conversation as resolved.
Show resolved Hide resolved

@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
}
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
oddsson marked this conversation as resolved.
Show resolved Hide resolved

@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
Loading