Skip to content

Commit

Permalink
Merge branch 'main' into ids-admin/add-legalrep-translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 19, 2024
2 parents 4370034 + 8926579 commit bf779ee
Show file tree
Hide file tree
Showing 43 changed files with 1,018 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
NationalRegistryClientModule,
} from '@island.is/clients/national-registry-v2'
import { CACHE_MANAGER } from '@nestjs/cache-manager'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { ConfigModule, XRoadConfig } from '@island.is/nest/config'
import { AirlineUser } from '../../../user/user.model'
import { createTestUser } from '../../../../../../test/createTestUser'
Expand Down Expand Up @@ -73,6 +74,12 @@ describe('DiscountController', () => {
getUser: () => ({}),
})),
},
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
})),
},
{
provide: FlightService,
useClass: jest.fn(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createTestUser } from '../../../../../../test/createTestUser'
import { getModelToken } from '@nestjs/sequelize'
import { ExplicitCode } from '../../discount.model'
import { AirDiscountSchemeScope } from '@island.is/auth/scopes'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { User as AuthUser } from '@island.is/auth-nest-tools'
import {
NationalRegistryService,
Expand Down Expand Up @@ -60,6 +61,12 @@ describe('DiscountService', () => {
create: () => ({}),
})),
},
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
})),
},
{
provide: FlightService,
useClass: jest.fn(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export class NationalRegistryService {
const response = await this.personApi.getIndividual(nationalId)

if (!response) {
this.logger.info('getUser individual not found', {
category: 'ads-backend',
})
return null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cache as CacheManager } from 'cache-manager'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { Test } from '@nestjs/testing'
import { User } from '../../user.model'
import { UserService } from '../../user.service'
Expand Down Expand Up @@ -50,6 +51,12 @@ describe('UserService', () => {
set: () => ({}),
})),
},
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
})),
},
],
}).compile()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from '../nationalRegistry'
import type { User as AuthUser } from '@island.is/auth-nest-tools'
import { info } from 'kennitala'
import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

const ONE_WEEK = 604800 // seconds
const CACHE_KEY = 'userService'
Expand All @@ -24,6 +26,8 @@ export class UserService {
constructor(
private readonly flightService: FlightService,
private readonly nationalRegistryService: NationalRegistryService,
@Inject(LOGGER_PROVIDER)
private readonly logger: Logger,
@Inject(CACHE_MANAGER) private readonly cacheManager: CacheManager,
) {}

Expand Down Expand Up @@ -118,9 +122,13 @@ export class UserService {
const result = (await Promise.all(allUsers)).filter(Boolean) as Array<User>

if (!result || result.length === 0) {
throw new Error(
'Could not find NationalRegistry records of neither User or relatives.',
this.logger.warn(
'National Registry records for the user or their relatives could not be found.',
{
category: 'ads-backend',
},
)
return []
}

return result
Expand Down
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'
Loading

0 comments on commit bf779ee

Please sign in to comment.