From 8435b541f1e1d15ccb9dc35035898beca220457e Mon Sep 17 00:00:00 2001 From: Thomas Trompette Date: Tue, 12 Nov 2024 18:39:49 +0100 Subject: [PATCH] Switch to crud action --- .../factories/workflow-action.factory.ts | 2 +- ...orkflow-create-record-action-input.type.ts | 6 ---- .../record-action.module.ts} | 2 +- .../record-operation.workflow-action.ts} | 19 +++++++++++- .../workflow-record-action-input.type.ts | 31 +++++++++++++++++++ .../workflow-record-action-settings.type.ts} | 2 +- .../types/workflow-action-settings.type.ts | 2 +- .../types/workflow-action.type.ts | 2 +- .../workflow-executor.module.ts | 2 +- 9 files changed, 55 insertions(+), 13 deletions(-) delete mode 100644 packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type.ts rename packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/{create-record/create-record-action.module.ts => record-operation/record-action.module.ts} (73%) rename packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/{create-record/create-record.workflow-action.ts => record-operation/record-operation.workflow-action.ts} (60%) create mode 100644 packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-input.type.ts rename packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/{create-record/types/workflow-create-record-action-settings.type.ts => record-operation/types/workflow-record-action-settings.type.ts} (75%) diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts index 080fe86effe20..5537ee60a9228 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts @@ -7,8 +7,8 @@ import { WorkflowStepExecutorExceptionCode, } from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception'; import { CodeWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/code/code.workflow-action'; -import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record.workflow-action'; import { SendEmailWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/send-email.workflow-action'; +import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-operation.workflow-action'; import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type'; @Injectable() diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type.ts deleted file mode 100644 index 2af44374ada7d..0000000000000 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type.ts +++ /dev/null @@ -1,6 +0,0 @@ -type ObjectRecord = Record; - -export type WorkflowCreateRecordActionInput = { - objectName: string; - objectRecord: ObjectRecord; -}; diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record-action.module.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-action.module.ts similarity index 73% rename from packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record-action.module.ts rename to packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-action.module.ts index 6a31eb1f8c102..0d5838e8e257b 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record-action.module.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-action.module.ts @@ -1,6 +1,6 @@ import { Module } from '@nestjs/common'; -import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record.workflow-action'; +import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-operation.workflow-action'; @Module({ providers: [CreateRecordWorkflowAction], diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-operation.workflow-action.ts similarity index 60% rename from packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record.workflow-action.ts rename to packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-operation.workflow-action.ts index 14899acc3461e..5084a8dd56f7d 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record.workflow-action.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-operation.workflow-action.ts @@ -3,7 +3,11 @@ import { Injectable } from '@nestjs/common'; import { WorkflowAction } from 'src/modules/workflow/workflow-executor/interfaces/workflow-action.interface'; import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager'; -import { WorkflowCreateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type'; +import { + WorkflowCreateRecordActionInput, + WorkflowRecordActionInput, + WorkflowRecordOperationType, +} from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-input.type'; import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-result.type'; @Injectable() @@ -11,6 +15,19 @@ export class CreateRecordWorkflowAction implements WorkflowAction { constructor(private readonly twentyORMManager: TwentyORMManager) {} async execute( + workflowActionInput: WorkflowRecordActionInput, + ): Promise { + switch (workflowActionInput.type) { + case WorkflowRecordOperationType.CREATE: + return this.createRecord(workflowActionInput); + default: + throw new Error( + `Unknown record operation type: ${workflowActionInput.type}`, + ); + } + } + + private async createRecord( workflowActionInput: WorkflowCreateRecordActionInput, ): Promise { const repository = await this.twentyORMManager.getRepository( diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-input.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-input.type.ts new file mode 100644 index 0000000000000..d613c357232b0 --- /dev/null +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-input.type.ts @@ -0,0 +1,31 @@ +type ObjectRecord = Record; + +export enum WorkflowRecordOperationType { + CREATE = 'Create', + UPDATE = 'Update', + DELETE = 'Delete', +} + +export type WorkflowCreateRecordActionInput = { + type: WorkflowRecordOperationType.CREATE; + objectName: string; + objectRecord: ObjectRecord; +}; + +export type WorkflowUpdateRecordActionInput = { + type: WorkflowRecordOperationType.UPDATE; + objectName: string; + objectRecord: ObjectRecord; + objectRecordId: string; +}; + +export type WorkflowDeleteRecordActionInput = { + type: WorkflowRecordOperationType.DELETE; + objectName: string; + objectRecordId: string; +}; + +export type WorkflowRecordActionInput = + | WorkflowCreateRecordActionInput + | WorkflowUpdateRecordActionInput + | WorkflowDeleteRecordActionInput; diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-settings.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-settings.type.ts similarity index 75% rename from packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-settings.type.ts rename to packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-settings.type.ts index 3f4fdae5236b3..321f7e172b67f 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-settings.type.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-settings.type.ts @@ -1,4 +1,4 @@ -import { WorkflowCreateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type'; +import { WorkflowCreateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-input.type'; import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type'; export type WorkflowCreateRecordActionSettings = BaseWorkflowActionSettings & { diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type.ts index 55a4ac7dae3b2..1b216cc6795b4 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type.ts @@ -1,6 +1,6 @@ import { WorkflowCodeActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/code/types/workflow-code-action-settings.type'; -import { WorkflowCreateRecordActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-settings.type'; import { WorkflowSendEmailActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/types/workflow-send-email-action-settings.type'; +import { WorkflowCreateRecordActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-settings.type'; export type OutputSchema = object; diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts index 2732d7b7c433a..3327a2675d21d 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts @@ -1,6 +1,6 @@ import { WorkflowCodeActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/code/types/workflow-code-action-settings.type'; -import { WorkflowCreateRecordActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-settings.type'; import { WorkflowSendEmailActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/types/workflow-send-email-action-settings.type'; +import { WorkflowCreateRecordActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-settings.type'; import { WorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type'; export enum WorkflowActionType { diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts index 18b9d4e10068c..c63766fcc7b73 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts @@ -4,8 +4,8 @@ import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/s import { WorkflowCommonModule } from 'src/modules/workflow/common/workflow-common.module'; import { WorkflowActionFactory } from 'src/modules/workflow/workflow-executor/factories/workflow-action.factory'; import { CodeActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/code/code-action.module'; -import { CreateRecordActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record-action.module'; import { SendEmailActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/send-email-action.module'; +import { CreateRecordActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-action.module'; import { WorkflowExecutorWorkspaceService } from 'src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service'; @Module({