Skip to content

Commit

Permalink
Add /document prefix to document path (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Sep 20, 2023
1 parent 8b2879c commit a6d46d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/controllers/file-upload/file-upload.controller.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -14,8 +14,8 @@ export class FileUploadController {
async uploadFile(@Body() input: {name: string, parentId: string}, @UploadedFile() file: Express.Multer.File): Promise<DocumentOutputModel> {

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')
Expand All @@ -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)});
}
}
2 changes: 1 addition & 1 deletion src/services/kyc-case/kyc-case-management.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class KycCaseManagementApi {
abstract getCase(id: string): Promise<KycCaseModel>;
abstract createCase(customer: CustomerModel): Promise<KycCaseModel>;
abstract getDocument(id: string): Promise<DocumentModel>;
abstract addDocumentToCase(id: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream): Promise<DocumentModel>;
abstract addDocumentToCase(id: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream, pathPrefix?: string): Promise<DocumentModel>;
abstract removeDocumentFromCase(id: string, documentId: string): Promise<KycCaseModel>;
abstract reviewCase(input: ReviewCaseModel): Promise<KycCaseModel>;
abstract approveCase(input: ApproveCaseModel): Promise<KycCaseModel>;
Expand Down
4 changes: 2 additions & 2 deletions src/services/kyc-case/kyc-case-management.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export class KycCaseManagementMock implements KycCaseManagementApi {
return newCase;
}

async addDocumentToCase(caseId: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream): Promise<DocumentModel> {
async addDocumentToCase(caseId: string, documentName: string, document: DocumentRef | DocumentContent | DocumentStream, pathPrefix: string = ''): Promise<DocumentModel> {
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);

Expand Down

0 comments on commit a6d46d3

Please sign in to comment.