From c35e9cbfbd2a7ba33380966f1fe57dcecfd2e3b6 Mon Sep 17 00:00:00 2001 From: Eric Camellini Date: Wed, 5 Jun 2024 15:24:03 +0200 Subject: [PATCH] IMN-601 Fixing contract name creation date (#610) --- .../src/services/agreementContractBuilder.ts | 14 +++++++++----- .../src/services/agreementService.ts | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/agreement-process/src/services/agreementContractBuilder.ts b/packages/agreement-process/src/services/agreementContractBuilder.ts index 41ffc38555..8fcfe1ef34 100644 --- a/packages/agreement-process/src/services/agreementContractBuilder.ts +++ b/packages/agreement-process/src/services/agreementContractBuilder.ts @@ -27,6 +27,7 @@ import { genericError, tenantAttributeType, unsafeBrandId, + AgreementDocument, } from "pagopa-interop-models"; import { UserResponse, @@ -40,7 +41,6 @@ import { userNotFound, } from "../model/domain/errors.js"; import { UpdateAgreementSeed } from "../model/domain/models.js"; -import { ApiAgreementDocumentSeed } from "../model/types.js"; import { AgreementProcessConfig } from "../utilities/config.js"; import { ReadModelService } from "./readModelService.js"; @@ -64,10 +64,11 @@ const retrieveUser = async ( const createAgreementDocumentName = ( consumerId: TenantId, - producerId: TenantId + producerId: TenantId, + documentCreatedAt: Date ): string => `${consumerId}_${producerId}_${formatDateyyyyMMddHHmmss( - new Date() + documentCreatedAt )}_agreement_contract.pdf`; const getAttributeInvolved = async ( @@ -314,7 +315,7 @@ export const contractBuilder = ( consumer: Tenant, producer: Tenant, seed: UpdateAgreementSeed - ): Promise => { + ): Promise => { const templateFilePath = path.resolve( dirname, "..", @@ -338,9 +339,11 @@ export const contractBuilder = ( ); const documentId = generateId(); + const documentCreatedAt = new Date(); const documentName = createAgreementDocumentName( agreement.consumerId, - agreement.producerId + agreement.producerId, + documentCreatedAt ); const documentPath = await fileManager.storeBytes( @@ -358,6 +361,7 @@ export const contractBuilder = ( contentType: CONTENT_TYPE_PDF, prettyName: AGREEMENT_CONTRACT_PRETTY_NAME, path: documentPath, + createdAt: documentCreatedAt, }; }, }; diff --git a/packages/agreement-process/src/services/agreementService.ts b/packages/agreement-process/src/services/agreementService.ts index 213e7adc98..a1e5ecde22 100644 --- a/packages/agreement-process/src/services/agreementService.ts +++ b/packages/agreement-process/src/services/agreementService.ts @@ -1214,7 +1214,7 @@ async function addContractOnFirstActivation( return { ...agreement, - contract: apiAgreementDocumentToAgreementDocument(contract), + contract, }; }