Skip to content

Commit

Permalink
Rewrites create case file api
Browse files Browse the repository at this point in the history
  • Loading branch information
gudjong committed Nov 29, 2024
1 parent 41dd5db commit 38e1e7b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 27 deletions.
38 changes: 25 additions & 13 deletions apps/judicial-system/api/src/app/modules/backend/backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CaseFile> {
return this.post(`case/${id}/file`, createFile)
}

createDefendantCaseFile(
id: string,
createFile: unknown,
defendantId?: string,
civilClaimantId?: string,
defendantId: string,
): Promise<CaseFile> {
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<CaseFile> {
return this.post(
`case/${id}/civilClaimant/${civilClaimantId}/file`,
createFile,
)
}

getCaseFileSignedUrl(
Expand Down Expand Up @@ -446,13 +454,17 @@ export class BackendService extends DataSource<{ req: Request }> {
limitedAccessCreateCaseFile(
id: string,
createFile: unknown,
): Promise<CaseFile> {
return this.post(`case/${id}/limitedAccess/file`, createFile)
}

limitedAccessCreateCivilClaimantCaseFile(
id: string,
createFile: unknown,
civilClaimantId?: string,
): Promise<CaseFile> {
const connectionInjection = civilClaimantId
? `/civilClaimant/${civilClaimantId}`
: ''
return this.post(
`case/${id}/limitedAccess${connectionInjection}/file`,
`case/${id}/limitedAccess$/civilClaimant/${civilClaimantId}/file`,
createFile,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
51 changes: 48 additions & 3 deletions apps/judicial-system/api/src/app/modules/file/file.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -65,17 +67,60 @@ export class FileResolver {
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<CaseFile> {
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<CaseFile> {
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<CaseFile> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -63,6 +64,26 @@ export class LimitedAccessFileResolver {
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<CaseFile> {
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<CaseFile> {
const { caseId, civilClaimantId, ...createFile } = input

Expand All @@ -71,7 +92,7 @@ export class LimitedAccessFileResolver {
return this.auditTrailService.audit(
user.id,
AuditedAction.CREATE_FILE,
backendService.limitedAccessCreateCaseFile(
backendService.limitedAccessCreateCivilClaimantCaseFile(
caseId,
createFile,
civilClaimantId,
Expand Down

0 comments on commit 38e1e7b

Please sign in to comment.