From 7ec16143f5163372df37b4b6fc67c83982ee5c4b Mon Sep 17 00:00:00 2001 From: Anantshree Chandola Date: Fri, 7 Mar 2025 12:18:33 +0530 Subject: [PATCH] delete constant from all envs --- server/src/modules/organization-constants/controller.ts | 2 +- server/src/modules/organization-constants/util.service.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/modules/organization-constants/controller.ts b/server/src/modules/organization-constants/controller.ts index 39862dee29..894ed5da88 100644 --- a/server/src/modules/organization-constants/controller.ts +++ b/server/src/modules/organization-constants/controller.ts @@ -113,7 +113,7 @@ export class OrganizationConstantController implements IOrganizationConstantCont async delete(@User() user, @Param('id') constantId, @Query('environmentId') environmentId) { const { organizationId } = user; - await this.organizationConstantsService.delete(constantId, organizationId, environmentId); + await this.organizationConstantsService.delete(constantId, organizationId); return { statusCode: 204 }; } diff --git a/server/src/modules/organization-constants/util.service.ts b/server/src/modules/organization-constants/util.service.ts index bf81f5daaa..6a6afb0bc4 100644 --- a/server/src/modules/organization-constants/util.service.ts +++ b/server/src/modules/organization-constants/util.service.ts @@ -84,7 +84,7 @@ export class OrganizationConstantsUtilService implements IOrganizationConstantsU async deleteOrgEnvironmentConstant( constantId: string, organizationId: string, - environmentId: string + environmentId?: string ): Promise { return await dbTransactionWrap(async (manager: EntityManager) => { const constantToDelete = await this.organizationConstantRepository.findOneByIdAndOrganizationId( @@ -95,6 +95,11 @@ export class OrganizationConstantsUtilService implements IOrganizationConstantsU throw new Error('Constant not found'); } + // If no environmentId is provided, delete the constant from all environments + if (!environmentId) { + return this.organizationConstantRepository.deleteOneById(constantId); + } + if (constantToDelete.orgEnvironmentConstantValues.length === 1) { return this.organizationConstantRepository.deleteOneById(constantId); } else {