Skip to content

Commit

Permalink
Switch to crud action
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Nov 12, 2024
1 parent 6fb54ae commit 4b72d8f
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ 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 { RecordOperationWorkflowAction } 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()
export class WorkflowActionFactory {
constructor(
private readonly codeWorkflowAction: CodeWorkflowAction,
private readonly sendEmailWorkflowAction: SendEmailWorkflowAction,
private readonly createRecordWorkflowAction: CreateRecordWorkflowAction,
private readonly recordOperationWorkflowAction: RecordOperationWorkflowAction,
) {}

get(stepType: WorkflowActionType): WorkflowAction {
Expand All @@ -25,8 +25,8 @@ export class WorkflowActionFactory {
return this.codeWorkflowAction;
case WorkflowActionType.SEND_EMAIL:
return this.sendEmailWorkflowAction;
case WorkflowActionType.CREATE_RECORD:
return this.createRecordWorkflowAction;
case WorkflowActionType.RECORD_OPERATION:
return this.recordOperationWorkflowAction;
default:
throw new WorkflowStepExecutorException(
`Workflow step executor not found for step type '${stepType}'`,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';

import { RecordOperationWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/record-operation.workflow-action';

@Module({
providers: [RecordOperationWorkflowAction],
exports: [RecordOperationWorkflowAction],
})
export class RecordOperationActionModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@ 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,
WorkflowRecordOperationActionInput,
WorkflowRecordOperationType,
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-operation-action-input.type';
import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-result.type';

@Injectable()
export class CreateRecordWorkflowAction implements WorkflowAction {
export class RecordOperationWorkflowAction implements WorkflowAction {
constructor(private readonly twentyORMManager: TwentyORMManager) {}

async execute(
workflowActionInput: WorkflowRecordOperationActionInput,
): Promise<WorkflowActionResult> {
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<WorkflowActionResult> {
const repository = await this.twentyORMManager.getRepository(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type ObjectRecord = Record<string, any>;

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 WorkflowRecordOperationActionInput =
| WorkflowCreateRecordActionInput
| WorkflowUpdateRecordActionInput
| WorkflowDeleteRecordActionInput;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { WorkflowRecordOperationActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-operation-action-input.type';
import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type';

export type WorkflowRecordOperationActionSettings =
BaseWorkflowActionSettings & {
input: WorkflowRecordOperationActionInput;
};
Original file line number Diff line number Diff line change
@@ -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 { WorkflowRecordOperationActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-operation-action-settings.type';

export type OutputSchema = object;

Expand All @@ -20,4 +20,4 @@ export type BaseWorkflowActionSettings = {
export type WorkflowActionSettings =
| WorkflowSendEmailActionSettings
| WorkflowCodeActionSettings
| WorkflowCreateRecordActionSettings;
| WorkflowRecordOperationActionSettings;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 { WorkflowRecordOperationActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-operation-action-settings.type';
import { WorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type';

export enum WorkflowActionType {
CODE = 'CODE',
SEND_EMAIL = 'SEND_EMAIL',
CREATE_RECORD = 'CREATE_RECORD',
RECORD_OPERATION = 'RECORD_OPERATION',
}

type BaseWorkflowAction = {
Expand All @@ -27,12 +27,12 @@ export type WorkflowSendEmailAction = BaseWorkflowAction & {
settings: WorkflowSendEmailActionSettings;
};

export type WorkflowCreateRecordAction = BaseWorkflowAction & {
type: WorkflowActionType.CREATE_RECORD;
settings: WorkflowCreateRecordActionSettings;
export type WorkflowRecordOperationAction = BaseWorkflowAction & {
type: WorkflowActionType.RECORD_OPERATION;
settings: WorkflowRecordOperationActionSettings;
};

export type WorkflowAction =
| WorkflowCodeAction
| WorkflowSendEmailAction
| WorkflowCreateRecordAction;
| WorkflowRecordOperationAction;
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ 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 { RecordOperationActionModule } 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({
imports: [
WorkflowCommonModule,
CodeActionModule,
SendEmailActionModule,
CreateRecordActionModule,
RecordOperationActionModule,
],
providers: [
WorkflowExecutorWorkspaceService,
Expand Down

0 comments on commit 4b72d8f

Please sign in to comment.