Add position in run / version + block creation from generated API (#11318)
- Add position during workflow version / creation. It will allow to have the versions and runs ordered - Block the creation from generated api for versions. We use workflow post hooks or create from draft
This commit is contained in:
+4
-2
@@ -1,11 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { RecordPositionModule } from 'src/engine/core-modules/record-position/record-position.module';
|
||||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
||||
import { WorkflowCommonModule } from 'src/modules/workflow/common/workflow-common.module';
|
||||
import { WorkflowRunWorkspaceService } from 'src/modules/workflow/workflow-runner/workflow-run/workflow-run.workspace-service';
|
||||
|
||||
@Module({
|
||||
imports: [WorkflowCommonModule],
|
||||
providers: [WorkflowRunWorkspaceService],
|
||||
imports: [WorkflowCommonModule, RecordPositionModule],
|
||||
providers: [WorkflowRunWorkspaceService, ScopedWorkspaceContextFactory],
|
||||
exports: [WorkflowRunWorkspaceService],
|
||||
})
|
||||
export class WorkflowRunModule {}
|
||||
|
||||
+24
@@ -1,6 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { RecordPositionService } from 'src/engine/core-modules/record-position/services/record-position.service';
|
||||
import { ActorMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import {
|
||||
StepOutput,
|
||||
@@ -21,6 +23,8 @@ export class WorkflowRunWorkspaceService {
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly workflowCommonWorkspaceService: WorkflowCommonWorkspaceService,
|
||||
private readonly recordPositionService: RecordPositionService,
|
||||
private readonly scopedWorkspaceContextFactory: ScopedWorkspaceContextFactory,
|
||||
) {}
|
||||
|
||||
async createWorkflowRun({
|
||||
@@ -64,6 +68,25 @@ export class WorkflowRunWorkspaceService {
|
||||
},
|
||||
});
|
||||
|
||||
const workspaceId =
|
||||
this.scopedWorkspaceContextFactory.create()?.workspaceId;
|
||||
|
||||
if (!workspaceId) {
|
||||
throw new WorkflowRunException(
|
||||
'Workspace id is invalid',
|
||||
WorkflowRunExceptionCode.WORKFLOW_RUN_INVALID,
|
||||
);
|
||||
}
|
||||
|
||||
const position = await this.recordPositionService.buildRecordPosition({
|
||||
value: 'first',
|
||||
objectMetadata: {
|
||||
isCustom: false,
|
||||
nameSingular: 'workflowRun',
|
||||
},
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
return (
|
||||
await workflowRunRepository.save({
|
||||
name: `#${workflowRunCount + 1} - ${workflow.name}`,
|
||||
@@ -71,6 +94,7 @@ export class WorkflowRunWorkspaceService {
|
||||
createdBy,
|
||||
workflowId: workflow.id,
|
||||
status: WorkflowRunStatus.NOT_STARTED,
|
||||
position,
|
||||
})
|
||||
).id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user