Skip to content

Commit

Permalink
Fix zero project ids to bulk inclusion bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahdigh committed Jun 26, 2024
1 parent 827a3f1 commit 187fe8f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/flow/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 187fe8f

Please sign in to comment.