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 {