Update workflow run step (#11125)

Currently, when filling the form, values are not saved in the action
settings. This is an issue because we do not see the response in the
node settings, only in the output of the step.

This PR:
- adds a new endpoint to update a step in the run flow output
- updates this flow when a step is updated



https://github.com/user-attachments/assets/2e74a010-a0d2-4b87-bd1f-1c91f7ca6b60

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This commit is contained in:
Thomas Trompette
2025-03-24 17:42:15 +01:00
committed by GitHub
parent 0656b640d7
commit 049a065307
12 changed files with 266 additions and 37 deletions

View File

@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { v4 } from 'uuid';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import { v4 } from 'uuid';
import { BASE_TYPESCRIPT_PROJECT_INPUT_SCHEMA } from 'src/engine/core-modules/serverless/drivers/constants/base-typescript-project-input-schema';
import { WorkflowActionDTO } from 'src/engine/core-modules/workflow/dtos/workflow-step.dto';

View File

@ -9,6 +9,7 @@ import {
WorkflowRunWorkspaceEntity,
} from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
import { WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
import {
WorkflowRunException,
WorkflowRunExceptionCode,
@ -164,6 +165,54 @@ export class WorkflowRunWorkspaceService {
});
}
async updateWorkflowRunStep({
workflowRunId,
step,
}: {
workflowRunId: string;
step: WorkflowAction;
}) {
const workflowRunRepository =
await this.twentyORMManager.getRepository<WorkflowRunWorkspaceEntity>(
'workflowRun',
);
const workflowRunToUpdate = await workflowRunRepository.findOneBy({
id: workflowRunId,
});
if (!workflowRunToUpdate) {
throw new WorkflowRunException(
'No workflow run to update',
WorkflowRunExceptionCode.WORKFLOW_RUN_NOT_FOUND,
);
}
if (
workflowRunToUpdate.status === WorkflowRunStatus.COMPLETED ||
workflowRunToUpdate.status === WorkflowRunStatus.FAILED
) {
throw new WorkflowRunException(
'Cannot update steps of a completed or failed workflow run',
WorkflowRunExceptionCode.INVALID_OPERATION,
);
}
const updatedSteps = workflowRunToUpdate.output?.flow?.steps?.map(
(existingStep) => (step.id === existingStep.id ? step : existingStep),
);
return workflowRunRepository.update(workflowRunToUpdate.id, {
output: {
...(workflowRunToUpdate.output ?? {}),
flow: {
...(workflowRunToUpdate.output?.flow ?? {}),
steps: updatedSteps,
},
},
});
}
async getWorkflowRunOrFail(
workflowRunId: string,
): Promise<WorkflowRunWorkspaceEntity> {