From 187fe8f7dac3fb28e20c7cdaa90c8f76dba093fb Mon Sep 17 00:00:00 2001 From: Mahdi Date: Wed, 26 Jun 2024 14:09:11 +0330 Subject: [PATCH] Fix zero project ids to bulk inclusion bug --- src/flow/flow.service.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/flow/flow.service.ts b/src/flow/flow.service.ts index 77249bb..d798d9a 100644 --- a/src/flow/flow.service.ts +++ b/src/flow/flow.service.ts @@ -201,17 +201,29 @@ export class FlowService { const parentId = projects[0]?.parentId; + const minimumInclusion = parentId + ? await this.getMinimumIncludedProjects(parentId) + : 2; + + if (ids.length === 0) + throw new HttpException( + { + error: `You need to include at least ${minimumInclusion} projects`, + pwCode: 'pw1000', + minimum: minimumInclusion, + }, + HttpStatus.FORBIDDEN, + ); + if (new Set(projects.map((el) => el?.parentId)).size !== 1 || !parentId) throw new BadRequestException( 'All projects should share the same parent', ); - const minimumInclusion = await this.getMinimumIncludedProjects(parentId); - if (new Set(ids).size < minimumInclusion) throw new HttpException( { - error: `You need to include at least ${minimumInclusion} projets`, + error: `You need to include at least ${minimumInclusion} projects`, pwCode: 'pw1000', minimum: minimumInclusion, }, @@ -328,7 +340,7 @@ export class FlowService { ) throw new HttpException( { - error: `You need to include at least ${minimumInclusion} projets`, + error: `You need to include at least ${minimumInclusion} projects`, pwCode: 'pw1000', minimum: minimumInclusion, },