diff --git a/src/modules/proposal/services/__tests__/proposal-misc.service.spec.ts b/src/modules/proposal/services/__tests__/proposal-misc.service.spec.ts index 989d076..9016bb1 100644 --- a/src/modules/proposal/services/__tests__/proposal-misc.service.spec.ts +++ b/src/modules/proposal/services/__tests__/proposal-misc.service.spec.ts @@ -18,7 +18,7 @@ import { IGetKeycloakUser } from 'src/modules/user/types/keycloak-user.interface import { addHistoryItemForProposalLock, addHistoryItemForStatus } from '../../utils/proposal-history.util'; import { validateStatusChange } from '../../utils/validate-status-change.util'; import { setImmediate } from 'timers'; -import { addUpload, getBlobName, getProposalBlobName } from '../../utils/proposal.utils'; +import { addUpload, getBlobName } from '../../utils/proposal.utils'; import { UseCaseUpload } from '../../enums/upload-type.enum'; import { SupportedMimetype } from '../../enums/supported-mime-type.enum'; import { FdpgChecklistSetDto } from '../../dto/proposal/fdpg-checklist.dto'; @@ -50,7 +50,6 @@ jest.mock('../../utils/proposal-history.util', () => ({ jest.mock('../../utils/proposal.utils', () => ({ addUpload: jest.fn(), getBlobName: jest.fn().mockReturnValue('blobName'), - getProposalBlobName: jest.fn().mockReturnValue('blobName_proposal'), })); jest.mock('../../utils/validate-fdpg-check-status.util', () => ({ @@ -363,8 +362,7 @@ describe('ProposalMiscService', () => { originalname: `${proposalDocument.projectAbbreviation}_proposal.pdf`, mimetype: SupportedMimetype.Pdf, }); - expect(storageService.uploadFile).toHaveBeenCalledWith('blobName_proposal', expectedFile, request.user); - expect(getProposalBlobName).toHaveBeenCalledWith(proposalId, projectAbbreviation, UseCaseUpload.ProposalPDF); + expect(storageService.uploadFile).toHaveBeenCalledWith('blobName', expectedFile, request.user); expect(addUpload).toHaveBeenCalledWith(proposalDocument, expect.anything()); }); }); diff --git a/src/modules/proposal/services/proposal-misc.service.ts b/src/modules/proposal/services/proposal-misc.service.ts index c29f100..13c12f2 100644 --- a/src/modules/proposal/services/proposal-misc.service.ts +++ b/src/modules/proposal/services/proposal-misc.service.ts @@ -23,7 +23,7 @@ import { UseCaseUpload } from '../enums/upload-type.enum'; import { addFdpgChecklist } from '../utils/add-fdpg-checklist.util'; import { flattenToLanguage } from '../utils/flatten-to-language.util'; import { addHistoryItemForProposalLock, addHistoryItemForStatus } from '../utils/proposal-history.util'; -import { addUpload, getBlobName, getProposalBlobName } from '../utils/proposal.utils'; +import { addUpload, getBlobName } from '../utils/proposal.utils'; import { validateFdpgCheckStatus } from '../utils/validate-fdpg-check-status.util'; import { validateStatusChange } from '../utils/validate-status-change.util'; import { ProposalCrudService } from './proposal-crud.service'; @@ -148,7 +148,7 @@ export class ProposalMiscService { mimetype: SupportedMimetype.Pdf, size: Buffer.byteLength(pdfBuffer), } as Express.Multer.File; - const pdfBlobName = getProposalBlobName(proposal._id, proposal.projectAbbreviation, UseCaseUpload.ProposalPDF); + const pdfBlobName = getBlobName(proposal._id, UseCaseUpload.ProposalPDF); await this.storageService.uploadFile(pdfBlobName, pdfFile, user); const pdfUpload = new UploadDto(pdfBlobName, pdfFile, UseCaseUpload.ProposalPDF, user); addUpload(proposal, pdfUpload); diff --git a/src/modules/proposal/utils/proposal.utils.ts b/src/modules/proposal/utils/proposal.utils.ts index 94c761d..166211d 100644 --- a/src/modules/proposal/utils/proposal.utils.ts +++ b/src/modules/proposal/utils/proposal.utils.ts @@ -1,4 +1,4 @@ -import { UploadType, UseCaseUpload } from '../enums/upload-type.enum'; +import { UploadType } from '../enums/upload-type.enum'; import { v4 as uuid } from 'uuid'; import { Proposal } from '../schema/proposal.schema'; import { UploadDto } from '../dto/upload.dto'; @@ -6,26 +6,14 @@ import { ReportDto } from '../dto/proposal/report.dto'; const getBasePath = (proposalId: string, type: UploadType): string => `proposal/${proposalId}/${type}/`; -export const getBlobName = (proposalId: string, type: UploadType, subId?: string): string => { - return `${getBasePath(proposalId, type)}${getSubPath(subId)}${uuid()}`; -}; - -export const getProposalBlobName = (proposalId: string, projectAbbreviation: string, type: UploadType) => { - if (type === UseCaseUpload.ProposalPDF) { - const blobInstanceName = `${projectAbbreviation}_proposal`; - - return `${getBasePath(proposalId, type)}${blobInstanceName}`; - } - - throw new Error( - `type '${type}' of proposalId '${proposalId}' does not match requirement '${UseCaseUpload.ProposalPDF}'`, - ); -}; - const getSubPath = (subId?: string): string => { return subId ? subId + '/' : ''; }; +export const getBlobName = (proposalId: string, type: UploadType, subId?: string): string => { + return `${getBasePath(proposalId, type)}${getSubPath(subId)}${uuid()}`; +}; + export const addUpload = (proposal: Proposal, upload: UploadDto): void => { if (proposal.uploads) { proposal.uploads.push(upload);