diff --git a/apps/judicial-system/api/src/app/modules/backend/backend.service.ts b/apps/judicial-system/api/src/app/modules/backend/backend.service.ts index 2a8571b7c250..5e679c80f99e 100644 --- a/apps/judicial-system/api/src/app/modules/backend/backend.service.ts +++ b/apps/judicial-system/api/src/app/modules/backend/backend.service.ts @@ -266,19 +266,27 @@ export class BackendService extends DataSource<{ req: Request }> { return this.post(`case/${id}/file/url`, createPresignedPost) } - createCaseFile( + createCaseFile(id: string, createFile: unknown): Promise { + return this.post(`case/${id}/file`, createFile) + } + + createDefendantCaseFile( id: string, createFile: unknown, - defendantId?: string, - civilClaimantId?: string, + defendantId: string, ): Promise { - const connectionInjection = defendantId - ? `/defendant/${defendantId}` - : civilClaimantId - ? `/civilClaimant/${civilClaimantId}` - : '' + return this.post(`case/${id}/defendant${defendantId}/file`, createFile) + } - return this.post(`case/${id}${connectionInjection}/file`, createFile) + createCivilClaimantCaseFile( + id: string, + createFile: unknown, + civilClaimantId?: string, + ): Promise { + return this.post( + `case/${id}/civilClaimant/${civilClaimantId}/file`, + createFile, + ) } getCaseFileSignedUrl( @@ -446,13 +454,17 @@ export class BackendService extends DataSource<{ req: Request }> { limitedAccessCreateCaseFile( id: string, createFile: unknown, + ): Promise { + return this.post(`case/${id}/limitedAccess/file`, createFile) + } + + limitedAccessCreateCivilClaimantCaseFile( + id: string, + createFile: unknown, civilClaimantId?: string, ): Promise { - const connectionInjection = civilClaimantId - ? `/civilClaimant/${civilClaimantId}` - : '' return this.post( - `case/${id}/limitedAccess${connectionInjection}/file`, + `case/${id}/limitedAccess$/civilClaimant/${civilClaimantId}/file`, createFile, ) } diff --git a/apps/judicial-system/api/src/app/modules/file/dto/createCivilClaimantFile.input.ts b/apps/judicial-system/api/src/app/modules/file/dto/createCivilClaimantFile.input.ts new file mode 100644 index 000000000000..a66e171df826 --- /dev/null +++ b/apps/judicial-system/api/src/app/modules/file/dto/createCivilClaimantFile.input.ts @@ -0,0 +1,12 @@ +import { Allow } from 'class-validator' + +import { Field, ID, InputType } from '@nestjs/graphql' + +import { CreateFileInput } from './createFile.input' + +@InputType() +export class CreateCivilClaimantFileInput extends CreateFileInput { + @Allow() + @Field(() => ID) + readonly civilClaimantId!: string +} diff --git a/apps/judicial-system/api/src/app/modules/file/dto/createDefendantFile.input.ts b/apps/judicial-system/api/src/app/modules/file/dto/createDefendantFile.input.ts new file mode 100644 index 000000000000..540e5ce719c3 --- /dev/null +++ b/apps/judicial-system/api/src/app/modules/file/dto/createDefendantFile.input.ts @@ -0,0 +1,12 @@ +import { Allow } from 'class-validator' + +import { Field, ID, InputType } from '@nestjs/graphql' + +import { CreateFileInput } from './createFile.input' + +@InputType() +export class CreateDefendantFileInput extends CreateFileInput { + @Allow() + @Field(() => ID) + readonly defendantId!: string +} diff --git a/apps/judicial-system/api/src/app/modules/file/dto/createFile.input.ts b/apps/judicial-system/api/src/app/modules/file/dto/createFile.input.ts index bd66872d061f..51137a3310e5 100644 --- a/apps/judicial-system/api/src/app/modules/file/dto/createFile.input.ts +++ b/apps/judicial-system/api/src/app/modules/file/dto/createFile.input.ts @@ -70,14 +70,4 @@ export class CreateFileInput { @IsOptional() @Field(() => String, { nullable: true }) readonly userGeneratedFilename?: string - - @Allow() - @IsOptional() - @Field(() => ID, { nullable: true }) - readonly defendantId?: string - - @Allow() - @IsOptional() - @Field(() => ID, { nullable: true }) - readonly civilClaimantId?: string } diff --git a/apps/judicial-system/api/src/app/modules/file/file.resolver.ts b/apps/judicial-system/api/src/app/modules/file/file.resolver.ts index 3a50398c9070..e59c2724125a 100644 --- a/apps/judicial-system/api/src/app/modules/file/file.resolver.ts +++ b/apps/judicial-system/api/src/app/modules/file/file.resolver.ts @@ -15,6 +15,8 @@ import { import type { User } from '@island.is/judicial-system/types' import { BackendService } from '../backend' +import { CreateCivilClaimantFileInput } from './dto/createCivilClaimantFile.input' +import { CreateDefendantFileInput } from './dto/createDefendantFile.input' import { CreateFileInput } from './dto/createFile.input' import { CreatePresignedPostInput } from './dto/createPresignedPost.input' import { DeleteFileInput } from './dto/deleteFile.input' @@ -65,17 +67,60 @@ export class FileResolver { @Context('dataSources') { backendService }: { backendService: BackendService }, ): Promise { - const { caseId, defendantId, civilClaimantId, ...createFile } = input + const { caseId, ...createFile } = input this.logger.debug(`Creating a file for case ${caseId}`) return this.auditTrailService.audit( user.id, AuditedAction.CREATE_FILE, - backendService.createCaseFile( + backendService.createCaseFile(caseId, createFile), + (file) => file.id, + ) + } + + @Mutation(() => CaseFile) + createDefendantFile( + @Args('input', { type: () => CreateDefendantFileInput }) + input: CreateDefendantFileInput, + @CurrentGraphQlUser() user: User, + @Context('dataSources') + { backendService }: { backendService: BackendService }, + ): Promise { + const { caseId, defendantId, ...createFile } = input + + this.logger.debug( + `Creating a file for case ${caseId} and defendant ${defendantId}`, + ) + + return this.auditTrailService.audit( + user.id, + AuditedAction.CREATE_FILE, + backendService.createDefendantCaseFile(caseId, createFile, defendantId), + (file) => file.id, + ) + } + + @Mutation(() => CaseFile) + createCivilClaimantFile( + @Args('input', { type: () => CreateCivilClaimantFileInput }) + input: CreateCivilClaimantFileInput, + @CurrentGraphQlUser() user: User, + @Context('dataSources') + { backendService }: { backendService: BackendService }, + ): Promise { + const { caseId, civilClaimantId, ...createFile } = input + + this.logger.debug( + `Creating a file for case ${caseId} and civil claimant ${civilClaimantId}`, + ) + + return this.auditTrailService.audit( + user.id, + AuditedAction.CREATE_FILE, + backendService.createCivilClaimantCaseFile( caseId, createFile, - defendantId, civilClaimantId, ), (file) => file.id, diff --git a/apps/judicial-system/api/src/app/modules/file/limitedAccessFile.resolver.ts b/apps/judicial-system/api/src/app/modules/file/limitedAccessFile.resolver.ts index 75c597e3ebea..70b8fda5e1a8 100644 --- a/apps/judicial-system/api/src/app/modules/file/limitedAccessFile.resolver.ts +++ b/apps/judicial-system/api/src/app/modules/file/limitedAccessFile.resolver.ts @@ -15,6 +15,7 @@ import { import type { User } from '@island.is/judicial-system/types' import { BackendService } from '../backend' +import { CreateCivilClaimantFileInput } from './dto/createCivilClaimantFile.input' import { CreateFileInput } from './dto/createFile.input' import { CreatePresignedPostInput } from './dto/createPresignedPost.input' import { DeleteFileInput } from './dto/deleteFile.input' @@ -63,6 +64,26 @@ export class LimitedAccessFileResolver { @CurrentGraphQlUser() user: User, @Context('dataSources') { backendService }: { backendService: BackendService }, + ): Promise { + const { caseId, ...createFile } = input + + this.logger.debug(`Creating a file for case ${caseId}`) + + return this.auditTrailService.audit( + user.id, + AuditedAction.CREATE_FILE, + backendService.limitedAccessCreateCaseFile(caseId, createFile), + (file) => file.id, + ) + } + + @Mutation(() => CaseFile) + limitedAccessCivilClaimantCreateFile( + @Args('input', { type: () => CreateCivilClaimantFileInput }) + input: CreateCivilClaimantFileInput, + @CurrentGraphQlUser() user: User, + @Context('dataSources') + { backendService }: { backendService: BackendService }, ): Promise { const { caseId, civilClaimantId, ...createFile } = input @@ -71,7 +92,7 @@ export class LimitedAccessFileResolver { return this.auditTrailService.audit( user.id, AuditedAction.CREATE_FILE, - backendService.limitedAccessCreateCaseFile( + backendService.limitedAccessCreateCivilClaimantCaseFile( caseId, createFile, civilClaimantId,