From 13b596a9becfba9ce62822c51bdd4ff88135feaf Mon Sep 17 00:00:00 2001 From: chavda-bhavik Date: Tue, 26 Mar 2024 16:59:00 +0530 Subject: [PATCH] fix: Customization entry sending null when creating new --- apps/api/src/app/template/template.controller.ts | 2 +- .../update-customization/update-customization.usecase.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app/template/template.controller.ts b/apps/api/src/app/template/template.controller.ts index d493ae3b4..627aa0086 100644 --- a/apps/api/src/app/template/template.controller.ts +++ b/apps/api/src/app/template/template.controller.ts @@ -289,7 +289,7 @@ export class TemplateController { async updateCustomizationRequest( @Param('templateId', ValidateMongoId) templateId: string, @Body() body: UpdateCustomizationRequestDto - ): Promise { + ) { return this.updateCustomization.execute(templateId, body); } diff --git a/apps/api/src/app/template/usecases/update-customization/update-customization.usecase.ts b/apps/api/src/app/template/usecases/update-customization/update-customization.usecase.ts index 7f0b45373..bf0f1b391 100644 --- a/apps/api/src/app/template/usecases/update-customization/update-customization.usecase.ts +++ b/apps/api/src/app/template/usecases/update-customization/update-customization.usecase.ts @@ -52,7 +52,7 @@ export class UpdateCustomization { } } - const customizationResult = await this.customizationRepository.findOneAndUpdate( + let customizationResult = await this.customizationRepository.findOneAndUpdate( { _templateId, }, @@ -60,6 +60,8 @@ export class UpdateCustomization { { upsert: true } ); + if (!customizationResult) customizationResult = await this.customizationRepository.findOne({ _templateId }); + return Object.assign(customizationResult, customizationUpdateData); }