diff --git a/src/controllers/file-upload/file-upload.controller.ts b/src/controllers/file-upload/file-upload.controller.ts index a654713..be44fe0 100644 --- a/src/controllers/file-upload/file-upload.controller.ts +++ b/src/controllers/file-upload/file-upload.controller.ts @@ -1,6 +1,6 @@ import {Body, Controller, Get, Param, Post, Res, StreamableFile, UploadedFile, UseInterceptors} from "@nestjs/common"; import {FileInterceptor} from "@nestjs/platform-express"; -import mime from "mime"; +import {getType} from "mime"; import {DocumentOutputModel, KycCaseManagementApi} from "../../services"; @@ -14,8 +14,8 @@ export class FileUploadController { async uploadFile(@Body() input: {name: string, parentId: string}, @UploadedFile() file: Express.Multer.File): Promise { return this.service - .addDocumentToCase(input.parentId, input.name, {content: file.buffer}) - .then(doc => ({id: doc.id, name: doc.name, path: `/document/${doc.path}`})); + .addDocumentToCase(input.parentId, input.name, {content: file.buffer}, '/document/') + .then(doc => ({id: doc.id, name: doc.name, path: `${doc.path}`})); } @Get(':id/:name') @@ -27,10 +27,10 @@ export class FileUploadController { const document = await this.service.getDocument(id); (res as any).set({ - 'Content-Type': mime.getType(document.name), + 'Content-Type': getType(document.name), 'Content-Disposition': `attachment; filename="${document.name}"` }) - return new StreamableFile(document.content, {type: mime.getType(document.name)}); + return new StreamableFile(document.content, {type: getType(document.name)}); } } diff --git a/src/services/kyc-case/kyc-case-management.api.ts b/src/services/kyc-case/kyc-case-management.api.ts index f79a3f5..e5dcd35 100644 --- a/src/services/kyc-case/kyc-case-management.api.ts +++ b/src/services/kyc-case/kyc-case-management.api.ts @@ -18,7 +18,7 @@ export abstract class KycCaseManagementApi { abstract getCase(id: string): Promise; abstract createCase(customer: CustomerModel): Promise; abstract getDocument(id: string): Promise; - abstract addDocumentToCase(id: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream): Promise; + abstract addDocumentToCase(id: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream, pathPrefix?: string): Promise; abstract removeDocumentFromCase(id: string, documentId: string): Promise; abstract reviewCase(input: ReviewCaseModel): Promise; abstract approveCase(input: ApproveCaseModel): Promise; diff --git a/src/services/kyc-case/kyc-case-management.mock.ts b/src/services/kyc-case/kyc-case-management.mock.ts index 6e58f9d..54b76f8 100644 --- a/src/services/kyc-case/kyc-case-management.mock.ts +++ b/src/services/kyc-case/kyc-case-management.mock.ts @@ -100,14 +100,14 @@ export class KycCaseManagementMock implements KycCaseManagementApi { return newCase; } - async addDocumentToCase(caseId: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream): Promise { + async addDocumentToCase(caseId: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream, pathPrefix: string = ''): Promise { const currentCase = await this.getCase(caseId); const id = '' + (currentCase.documents.length + 1); const documentId = `${caseId}-${id}`; const content = await this.loadDocument(document); - const newDoc = {id: documentId, name: documentName, path: `${documentId}/${documentName}`, content}; + const newDoc = {id: documentId, name: documentName, path: `${pathPrefix}${documentId}/${documentName}`, content}; currentCase.documents.push(newDoc);