Skip to content

Commit

Permalink
fix(workflow-mass-toggle): bug when toggling to false resolved
Browse files Browse the repository at this point in the history
Took 6 minutes
  • Loading branch information
Croos3r authored and Dorian Moy committed Nov 5, 2023
1 parent 286b97c commit f0236f6
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions backend/back/src/workflows/workflows.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,38 +310,9 @@ export class WorkflowsService {

async toggleWorkflows(workflowIds: string[], newState: boolean, ownerId: string) {
this.logger.log(`Toggling ${workflowIds.length} workflows to ${newState}`);
const { affected } = await this.workflowRepository.update(
{
id: In(workflowIds),
active: !newState,
ownerId,
},
{ active: () => `${newState}` },
);
if (newState) {
this.logger.log(`Launching ${workflowIds.length} workflows...`);
await Promise.all(
workflowIds.map(async (workflowId) => {
const workflow = await this.workflowRepository.findOne({
where: { id: workflowId, ownerId },
relations: { action: { area: true } },
});
await this.jobsService.launchWorkflowAction(workflow, ownerId);
await this.grpcService.onAction({
name: "area-on-workflow-toggle",
identifier: `area-on-workflow-toggle-${ownerId}`,
params: {
name: workflow.name,
},
});
}),
);
} else {
this.logger.log(`Stopping ${workflowIds.length} workflows...`);
const workflows = await this.workflowRepository.find({ where: { id: In(workflowIds) } });
await Promise.all(workflows.map(this.jobsService.stopWorkflowActionIfNecessary));
}
return affected > 0;
await Promise.all(workflowIds.map((workflowId) => this.toggleWorkflow(workflowId, newState, ownerId)));
this.logger.log(`Toggled ${workflowIds.length} workflows to ${newState}`);
return true;
}

async toggleWorkflow(workflowId: string, newState: boolean, ownerId: string) {
Expand Down

0 comments on commit f0236f6

Please sign in to comment.