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 8435b54
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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],
Expand Down
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,
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()
export class CreateRecordWorkflowAction implements WorkflowAction {
constructor(private readonly twentyORMManager: TwentyORMManager) {}

async execute(
workflowActionInput: WorkflowRecordActionInput,
): 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 WorkflowRecordActionInput =
| WorkflowCreateRecordActionInput
| WorkflowUpdateRecordActionInput
| WorkflowDeleteRecordActionInput;
Original file line number Diff line number Diff line change
@@ -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 & {
Expand Down
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 { WorkflowCreateRecordActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-operation/types/workflow-record-action-settings.type';

export type OutputSchema = object;

Expand Down
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 { 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 8435b54

Please sign in to comment.