mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-03 17:53:58 +03:00
Split record crud actions (#8930)
Having a global record crud action adds complex logic.
We decided to split those actions. I only kept a common folder / module
in backend.
⚠️ this may break existing workflows if these were using previous
actions!
This commit is contained in:
parent
229a93e41a
commit
e1a0259154
@ -76,8 +76,9 @@ export const WorkflowDiagramStepNodeBase = ({
|
||||
</StyledStepNodeLabelIconContainer>
|
||||
);
|
||||
}
|
||||
case 'RECORD_CRUD.UPDATE':
|
||||
case 'RECORD_CRUD.CREATE': {
|
||||
case 'CREATE_RECORD':
|
||||
case 'UPDATE_RECORD':
|
||||
case 'DELETE_RECORD': {
|
||||
return (
|
||||
<StyledStepNodeLabelIconContainer>
|
||||
<IconAddressBook
|
||||
@ -88,10 +89,6 @@ export const WorkflowDiagramStepNodeBase = ({
|
||||
</StyledStepNodeLabelIconContainer>
|
||||
);
|
||||
}
|
||||
|
||||
case 'RECORD_CRUD.DELETE': {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,10 @@ import {
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { assertUnreachable } from '@/workflow/utils/assertUnreachable';
|
||||
import { getStepDefinitionOrThrow } from '@/workflow/utils/getStepDefinitionOrThrow';
|
||||
import { WorkflowEditActionFormRecordCreate } from '@/workflow/workflow-actions/components/WorkflowEditActionFormRecordCreate';
|
||||
import { WorkflowEditActionFormRecordDelete } from '@/workflow/workflow-actions/components/WorkflowEditActionFormRecordDelete';
|
||||
import { WorkflowEditActionFormRecordUpdate } from '@/workflow/workflow-actions/components/WorkflowEditActionFormRecordUpdate';
|
||||
import { WorkflowEditActionFormCreateRecord } from '@/workflow/workflow-actions/components/WorkflowEditActionFormCreateRecord';
|
||||
import { WorkflowEditActionFormDeleteRecord } from '@/workflow/workflow-actions/components/WorkflowEditActionFormDeleteRecord';
|
||||
import { WorkflowEditActionFormSendEmail } from '@/workflow/workflow-actions/components/WorkflowEditActionFormSendEmail';
|
||||
import { isWorkflowRecordCreateAction } from '@/workflow/workflow-actions/utils/isWorkflowRecordCreateAction';
|
||||
import { isWorkflowRecordDeleteAction } from '@/workflow/workflow-actions/utils/isWorkflowRecordDeleteAction';
|
||||
import { isWorkflowRecordUpdateAction } from '@/workflow/workflow-actions/utils/isWorkflowRecordUpdateAction';
|
||||
import { WorkflowEditActionFormUpdateRecord } from '@/workflow/workflow-actions/components/WorkflowEditActionFormUpdateRecord';
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
import { RightDrawerSkeletonLoader } from '~/loading/components/RightDrawerSkeletonLoader';
|
||||
@ -107,42 +104,35 @@ export const WorkflowStepDetail = ({
|
||||
/>
|
||||
);
|
||||
}
|
||||
case 'RECORD_CRUD': {
|
||||
if (isWorkflowRecordCreateAction(stepDefinition.definition)) {
|
||||
return (
|
||||
<WorkflowEditActionFormRecordCreate
|
||||
action={stepDefinition.definition}
|
||||
actionOptions={props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case 'CREATE_RECORD': {
|
||||
return (
|
||||
<WorkflowEditActionFormCreateRecord
|
||||
action={stepDefinition.definition}
|
||||
actionOptions={props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (isWorkflowRecordUpdateAction(stepDefinition.definition)) {
|
||||
return (
|
||||
<WorkflowEditActionFormRecordUpdate
|
||||
action={stepDefinition.definition}
|
||||
actionOptions={props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case 'UPDATE_RECORD': {
|
||||
return (
|
||||
<WorkflowEditActionFormUpdateRecord
|
||||
action={stepDefinition.definition}
|
||||
actionOptions={props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (isWorkflowRecordDeleteAction(stepDefinition.definition)) {
|
||||
return (
|
||||
<WorkflowEditActionFormRecordDelete
|
||||
action={stepDefinition.definition}
|
||||
actionOptions={props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
case 'DELETE_RECORD': {
|
||||
return (
|
||||
<WorkflowEditActionFormDeleteRecord
|
||||
action={stepDefinition.definition}
|
||||
actionOptions={props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return assertUnreachable(
|
||||
stepDefinition.definition,
|
||||
`Expected the step to have an handler; ${JSON.stringify(stepDefinition)}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,17 +22,17 @@ export const ACTIONS: Array<{
|
||||
},
|
||||
{
|
||||
label: 'Create Record',
|
||||
type: 'RECORD_CRUD.CREATE',
|
||||
type: 'CREATE_RECORD',
|
||||
icon: IconAddressBook,
|
||||
},
|
||||
{
|
||||
label: 'Update Record',
|
||||
type: 'RECORD_CRUD.UPDATE',
|
||||
type: 'UPDATE_RECORD',
|
||||
icon: IconAddressBook,
|
||||
},
|
||||
{
|
||||
label: 'Delete Record',
|
||||
type: 'RECORD_CRUD.DELETE',
|
||||
type: 'DELETE_RECORD',
|
||||
icon: IconAddressBook,
|
||||
},
|
||||
];
|
||||
|
@ -32,34 +32,26 @@ export type WorkflowSendEmailActionSettings = BaseWorkflowActionSettings & {
|
||||
|
||||
type ObjectRecord = Record<string, any>;
|
||||
|
||||
export type WorkflowCreateRecordActionInput = {
|
||||
type: 'CREATE';
|
||||
objectName: string;
|
||||
objectRecord: ObjectRecord;
|
||||
export type WorkflowCreateRecordActionSettings = BaseWorkflowActionSettings & {
|
||||
input: {
|
||||
objectName: string;
|
||||
objectRecord: ObjectRecord;
|
||||
};
|
||||
};
|
||||
|
||||
export type WorkflowUpdateRecordActionInput = {
|
||||
type: 'UPDATE';
|
||||
objectName: string;
|
||||
objectRecord: ObjectRecord;
|
||||
objectRecordId: string;
|
||||
export type WorkflowUpdateRecordActionSettings = BaseWorkflowActionSettings & {
|
||||
input: {
|
||||
objectName: string;
|
||||
objectRecord: ObjectRecord;
|
||||
objectRecordId: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type WorkflowDeleteRecordActionInput = {
|
||||
type: 'DELETE';
|
||||
objectName: string;
|
||||
objectRecordId: string;
|
||||
};
|
||||
|
||||
export type WorkflowRecordCRUDActionInput =
|
||||
| WorkflowCreateRecordActionInput
|
||||
| WorkflowUpdateRecordActionInput
|
||||
| WorkflowDeleteRecordActionInput;
|
||||
|
||||
export type WorkflowRecordCRUDType = WorkflowRecordCRUDActionInput['type'];
|
||||
|
||||
export type WorkflowRecordCRUDActionSettings = BaseWorkflowActionSettings & {
|
||||
input: WorkflowRecordCRUDActionInput;
|
||||
export type WorkflowDeleteRecordActionSettings = BaseWorkflowActionSettings & {
|
||||
input: {
|
||||
objectName: string;
|
||||
objectRecordId: string;
|
||||
};
|
||||
};
|
||||
|
||||
type BaseWorkflowAction = {
|
||||
@ -78,35 +70,33 @@ export type WorkflowSendEmailAction = BaseWorkflowAction & {
|
||||
settings: WorkflowSendEmailActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowRecordCRUDAction = BaseWorkflowAction & {
|
||||
type: 'RECORD_CRUD';
|
||||
settings: WorkflowRecordCRUDActionSettings;
|
||||
export type WorkflowCreateRecordAction = BaseWorkflowAction & {
|
||||
type: 'CREATE_RECORD';
|
||||
settings: WorkflowCreateRecordActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowRecordCreateAction = WorkflowRecordCRUDAction & {
|
||||
settings: { input: { type: 'CREATE' } };
|
||||
export type WorkflowUpdateRecordAction = BaseWorkflowAction & {
|
||||
type: 'UPDATE_RECORD';
|
||||
settings: WorkflowUpdateRecordActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowRecordUpdateAction = WorkflowRecordCRUDAction & {
|
||||
settings: { input: { type: 'UPDATE' } };
|
||||
};
|
||||
|
||||
export type WorkflowRecordDeleteAction = WorkflowRecordCRUDAction & {
|
||||
settings: { input: { type: 'DELETE' } };
|
||||
export type WorkflowDeleteRecordAction = BaseWorkflowAction & {
|
||||
type: 'DELETE_RECORD';
|
||||
settings: WorkflowDeleteRecordActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowAction =
|
||||
| WorkflowCodeAction
|
||||
| WorkflowSendEmailAction
|
||||
| WorkflowRecordCRUDAction;
|
||||
| WorkflowCreateRecordAction
|
||||
| WorkflowUpdateRecordAction
|
||||
| WorkflowDeleteRecordAction;
|
||||
|
||||
export type WorkflowActionType = WorkflowAction['type'];
|
||||
|
||||
export type WorkflowStep = WorkflowAction;
|
||||
|
||||
export type WorkflowActionType =
|
||||
| Exclude<WorkflowAction['type'], WorkflowRecordCRUDAction['type']>
|
||||
| `${WorkflowRecordCRUDAction['type']}.${WorkflowRecordCRUDType}`;
|
||||
|
||||
export type WorkflowStepType = WorkflowActionType;
|
||||
export type WorkflowStepType = WorkflowStep['type'];
|
||||
|
||||
type BaseTrigger = {
|
||||
name?: string;
|
||||
|
@ -1,9 +1,5 @@
|
||||
import { TRIGGER_STEP_ID } from '@/workflow/constants/TriggerStepId';
|
||||
import {
|
||||
WorkflowActionType,
|
||||
WorkflowStep,
|
||||
WorkflowTrigger,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { WorkflowStep, WorkflowTrigger } from '@/workflow/types/Workflow';
|
||||
import {
|
||||
WorkflowDiagram,
|
||||
WorkflowDiagramEdge,
|
||||
@ -35,25 +31,12 @@ export const generateWorkflowDiagram = ({
|
||||
) => {
|
||||
const nodeId = step.id;
|
||||
|
||||
let nodeActionType: WorkflowActionType;
|
||||
if (step.type === 'RECORD_CRUD') {
|
||||
nodeActionType = `RECORD_CRUD.${step.settings.input.type}`;
|
||||
} else {
|
||||
nodeActionType = step.type;
|
||||
}
|
||||
|
||||
let nodeLabel = step.name;
|
||||
if (step.type === 'RECORD_CRUD') {
|
||||
// FIXME: use activeObjectMetadataItems to get labelSingular
|
||||
nodeLabel = `${capitalize(step.settings.input.type.toLowerCase())} ${capitalize(step.settings.input.objectName)}`;
|
||||
}
|
||||
|
||||
nodes.push({
|
||||
id: nodeId,
|
||||
data: {
|
||||
nodeType: 'action',
|
||||
actionType: nodeActionType,
|
||||
name: isDefined(step.name) ? step.name : nodeLabel,
|
||||
actionType: step.type,
|
||||
name: step.name,
|
||||
},
|
||||
position: {
|
||||
x: xPos,
|
||||
|
@ -5,7 +5,7 @@ import { FormFieldInput } from '@/object-record/record-field/components/FormFiel
|
||||
import { Select, SelectOption } from '@/ui/input/components/Select';
|
||||
import { WorkflowEditGenericFormBase } from '@/workflow/components/WorkflowEditGenericFormBase';
|
||||
import { WorkflowVariablePicker } from '@/workflow/components/WorkflowVariablePicker';
|
||||
import { WorkflowRecordCreateAction } from '@/workflow/types/Workflow';
|
||||
import { WorkflowCreateRecordAction } from '@/workflow/types/Workflow';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
@ -18,15 +18,15 @@ import { JsonValue } from 'type-fest';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
import { FieldMetadataType } from '~/generated/graphql';
|
||||
|
||||
type WorkflowEditActionFormRecordCreateProps = {
|
||||
action: WorkflowRecordCreateAction;
|
||||
type WorkflowEditActionFormCreateRecordProps = {
|
||||
action: WorkflowCreateRecordAction;
|
||||
actionOptions:
|
||||
| {
|
||||
readonly: true;
|
||||
}
|
||||
| {
|
||||
readonly?: false;
|
||||
onActionUpdate: (action: WorkflowRecordCreateAction) => void;
|
||||
onActionUpdate: (action: WorkflowCreateRecordAction) => void;
|
||||
};
|
||||
};
|
||||
|
||||
@ -35,10 +35,10 @@ type CreateRecordFormData = {
|
||||
[field: string]: unknown;
|
||||
};
|
||||
|
||||
export const WorkflowEditActionFormRecordCreate = ({
|
||||
export const WorkflowEditActionFormCreateRecord = ({
|
||||
action,
|
||||
actionOptions,
|
||||
}: WorkflowEditActionFormRecordCreateProps) => {
|
||||
}: WorkflowEditActionFormCreateRecordProps) => {
|
||||
const theme = useTheme();
|
||||
const { getIcon } = useIcons();
|
||||
|
||||
@ -118,7 +118,6 @@ export const WorkflowEditActionFormRecordCreate = ({
|
||||
settings: {
|
||||
...action.settings,
|
||||
input: {
|
||||
type: 'CREATE',
|
||||
objectName: updatedObjectName,
|
||||
objectRecord: updatedOtherFields,
|
||||
},
|
@ -2,7 +2,7 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte
|
||||
import { Select, SelectOption } from '@/ui/input/components/Select';
|
||||
import { WorkflowEditGenericFormBase } from '@/workflow/components/WorkflowEditGenericFormBase';
|
||||
import { WorkflowSingleRecordPicker } from '@/workflow/components/WorkflowSingleRecordPicker';
|
||||
import { WorkflowRecordDeleteAction } from '@/workflow/types/Workflow';
|
||||
import { WorkflowDeleteRecordAction } from '@/workflow/types/Workflow';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
@ -15,15 +15,15 @@ import {
|
||||
import { JsonValue } from 'type-fest';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
|
||||
type WorkflowEditActionFormRecordDeleteProps = {
|
||||
action: WorkflowRecordDeleteAction;
|
||||
type WorkflowEditActionFormDeleteRecordProps = {
|
||||
action: WorkflowDeleteRecordAction;
|
||||
actionOptions:
|
||||
| {
|
||||
readonly: true;
|
||||
}
|
||||
| {
|
||||
readonly?: false;
|
||||
onActionUpdate: (action: WorkflowRecordDeleteAction) => void;
|
||||
onActionUpdate: (action: WorkflowDeleteRecordAction) => void;
|
||||
};
|
||||
};
|
||||
|
||||
@ -32,10 +32,10 @@ type DeleteRecordFormData = {
|
||||
objectRecordId: string;
|
||||
};
|
||||
|
||||
export const WorkflowEditActionFormRecordDelete = ({
|
||||
export const WorkflowEditActionFormDeleteRecord = ({
|
||||
action,
|
||||
actionOptions,
|
||||
}: WorkflowEditActionFormRecordDeleteProps) => {
|
||||
}: WorkflowEditActionFormDeleteRecordProps) => {
|
||||
const theme = useTheme();
|
||||
const { getIcon } = useIcons();
|
||||
|
||||
@ -100,7 +100,6 @@ export const WorkflowEditActionFormRecordDelete = ({
|
||||
settings: {
|
||||
...action.settings,
|
||||
input: {
|
||||
type: 'DELETE',
|
||||
objectName: updatedObjectName,
|
||||
objectRecordId: updatedObjectRecordId ?? '',
|
||||
},
|
@ -2,7 +2,7 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte
|
||||
import { Select, SelectOption } from '@/ui/input/components/Select';
|
||||
import { WorkflowEditGenericFormBase } from '@/workflow/components/WorkflowEditGenericFormBase';
|
||||
import { WorkflowSingleRecordPicker } from '@/workflow/components/WorkflowSingleRecordPicker';
|
||||
import { WorkflowRecordUpdateAction } from '@/workflow/types/Workflow';
|
||||
import { WorkflowUpdateRecordAction } from '@/workflow/types/Workflow';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
@ -15,15 +15,15 @@ import {
|
||||
import { JsonValue } from 'type-fest';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
|
||||
type WorkflowEditActionFormRecordUpdateProps = {
|
||||
action: WorkflowRecordUpdateAction;
|
||||
type WorkflowEditActionFormUpdateRecordProps = {
|
||||
action: WorkflowUpdateRecordAction;
|
||||
actionOptions:
|
||||
| {
|
||||
readonly: true;
|
||||
}
|
||||
| {
|
||||
readonly?: false;
|
||||
onActionUpdate: (action: WorkflowRecordUpdateAction) => void;
|
||||
onActionUpdate: (action: WorkflowUpdateRecordAction) => void;
|
||||
};
|
||||
};
|
||||
|
||||
@ -33,10 +33,10 @@ type UpdateRecordFormData = {
|
||||
[field: string]: unknown;
|
||||
};
|
||||
|
||||
export const WorkflowEditActionFormRecordUpdate = ({
|
||||
export const WorkflowEditActionFormUpdateRecord = ({
|
||||
action,
|
||||
actionOptions,
|
||||
}: WorkflowEditActionFormRecordUpdateProps) => {
|
||||
}: WorkflowEditActionFormUpdateRecordProps) => {
|
||||
const theme = useTheme();
|
||||
const { getIcon } = useIcons();
|
||||
|
||||
@ -104,7 +104,6 @@ export const WorkflowEditActionFormRecordUpdate = ({
|
||||
settings: {
|
||||
...action.settings,
|
||||
input: {
|
||||
type: 'UPDATE',
|
||||
objectName: updatedObjectName,
|
||||
objectRecordId: updatedObjectRecordId ?? '',
|
||||
objectRecord: updatedOtherFields,
|
@ -1,81 +0,0 @@
|
||||
import {
|
||||
WorkflowCodeAction,
|
||||
WorkflowRecordCRUDAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { isWorkflowRecordCreateAction } from '../isWorkflowRecordCreateAction';
|
||||
|
||||
describe('isWorkflowRecordCreateAction', () => {
|
||||
it('returns false when providing an action that is not Record Create', () => {
|
||||
const action: WorkflowCodeAction = {
|
||||
type: 'CODE',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
retryOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
input: {
|
||||
serverlessFunctionId: '',
|
||||
serverlessFunctionVersion: '',
|
||||
serverlessFunctionInput: {},
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordCreateAction(action)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for Record Update', () => {
|
||||
const action: WorkflowRecordCRUDAction = {
|
||||
type: 'RECORD_CRUD',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: { value: false },
|
||||
retryOnFailure: { value: false },
|
||||
},
|
||||
input: {
|
||||
type: 'UPDATE',
|
||||
objectName: '',
|
||||
objectRecord: {},
|
||||
objectRecordId: '',
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordCreateAction(action)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for Record Create', () => {
|
||||
const action: WorkflowRecordCRUDAction = {
|
||||
type: 'RECORD_CRUD',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: { value: false },
|
||||
retryOnFailure: { value: false },
|
||||
},
|
||||
input: {
|
||||
type: 'CREATE',
|
||||
objectName: '',
|
||||
objectRecord: {},
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordCreateAction(action)).toBe(true);
|
||||
});
|
||||
});
|
@ -1,81 +0,0 @@
|
||||
import {
|
||||
WorkflowCodeAction,
|
||||
WorkflowRecordCRUDAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { isWorkflowRecordDeleteAction } from '../isWorkflowRecordDeleteAction';
|
||||
|
||||
describe('isWorkflowRecordDeleteAction', () => {
|
||||
it('returns false when providing an action that is not Record Delete', () => {
|
||||
const action: WorkflowCodeAction = {
|
||||
type: 'CODE',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
retryOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
input: {
|
||||
serverlessFunctionId: '',
|
||||
serverlessFunctionVersion: '',
|
||||
serverlessFunctionInput: {},
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordDeleteAction(action)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for Record Update', () => {
|
||||
const action: WorkflowRecordCRUDAction = {
|
||||
type: 'RECORD_CRUD',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: { value: false },
|
||||
retryOnFailure: { value: false },
|
||||
},
|
||||
input: {
|
||||
type: 'UPDATE',
|
||||
objectName: '',
|
||||
objectRecord: {},
|
||||
objectRecordId: '',
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordDeleteAction(action)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for Record Delete', () => {
|
||||
const action: WorkflowRecordCRUDAction = {
|
||||
type: 'RECORD_CRUD',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: { value: false },
|
||||
retryOnFailure: { value: false },
|
||||
},
|
||||
input: {
|
||||
type: 'DELETE',
|
||||
objectName: '',
|
||||
objectRecordId: '',
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordDeleteAction(action)).toBe(true);
|
||||
});
|
||||
});
|
@ -1,81 +0,0 @@
|
||||
import {
|
||||
WorkflowCodeAction,
|
||||
WorkflowRecordCRUDAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { isWorkflowRecordUpdateAction } from '../isWorkflowRecordUpdateAction';
|
||||
|
||||
describe('isWorkflowRecordUpdateAction', () => {
|
||||
it('returns false when providing an action that is not Record Create', () => {
|
||||
const action: WorkflowCodeAction = {
|
||||
type: 'CODE',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
retryOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
input: {
|
||||
serverlessFunctionId: '',
|
||||
serverlessFunctionVersion: '',
|
||||
serverlessFunctionInput: {},
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordUpdateAction(action)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for Record Update', () => {
|
||||
const action: WorkflowRecordCRUDAction = {
|
||||
type: 'RECORD_CRUD',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: { value: false },
|
||||
retryOnFailure: { value: false },
|
||||
},
|
||||
input: {
|
||||
type: 'UPDATE',
|
||||
objectName: '',
|
||||
objectRecord: {},
|
||||
objectRecordId: '',
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordUpdateAction(action)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for Record Create', () => {
|
||||
const action: WorkflowRecordCRUDAction = {
|
||||
type: 'RECORD_CRUD',
|
||||
id: '',
|
||||
name: '',
|
||||
settings: {
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: { value: false },
|
||||
retryOnFailure: { value: false },
|
||||
},
|
||||
input: {
|
||||
type: 'CREATE',
|
||||
objectName: '',
|
||||
objectRecord: {},
|
||||
},
|
||||
outputSchema: {},
|
||||
},
|
||||
valid: true,
|
||||
};
|
||||
|
||||
expect(isWorkflowRecordUpdateAction(action)).toBe(false);
|
||||
});
|
||||
});
|
@ -1,12 +0,0 @@
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowRecordCreateAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
|
||||
export const isWorkflowRecordCreateAction = (
|
||||
action: WorkflowAction,
|
||||
): action is WorkflowRecordCreateAction => {
|
||||
return (
|
||||
action.type === 'RECORD_CRUD' && action.settings.input.type === 'CREATE'
|
||||
);
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowRecordDeleteAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
|
||||
export const isWorkflowRecordDeleteAction = (
|
||||
action: WorkflowAction,
|
||||
): action is WorkflowRecordDeleteAction => {
|
||||
return (
|
||||
action.type === 'RECORD_CRUD' && action.settings.input.type === 'DELETE'
|
||||
);
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowRecordUpdateAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
|
||||
export const isWorkflowRecordUpdateAction = (
|
||||
action: WorkflowAction,
|
||||
): action is WorkflowRecordUpdateAction => {
|
||||
return (
|
||||
action.type === 'RECORD_CRUD' && action.settings.input.type === 'UPDATE'
|
||||
);
|
||||
};
|
@ -18,7 +18,6 @@ import {
|
||||
} from 'src/modules/workflow/common/exceptions/workflow-version-step.exception';
|
||||
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowBuilderWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-builder.workspace-service';
|
||||
import { WorkflowRecordCRUDType } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type';
|
||||
import {
|
||||
WorkflowAction,
|
||||
@ -126,7 +125,7 @@ export class WorkflowVersionStepWorkspaceService {
|
||||
},
|
||||
};
|
||||
}
|
||||
case `${WorkflowActionType.RECORD_CRUD}.${WorkflowRecordCRUDType.CREATE}`: {
|
||||
case WorkflowActionType.CREATE_RECORD: {
|
||||
const activeObjectMetadataItem =
|
||||
await this.objectMetadataRepository.findOne({
|
||||
where: { workspaceId, isActive: true, isSystem: false },
|
||||
@ -135,19 +134,18 @@ export class WorkflowVersionStepWorkspaceService {
|
||||
return {
|
||||
id: newStepId,
|
||||
name: 'Create Record',
|
||||
type: WorkflowActionType.RECORD_CRUD,
|
||||
type: WorkflowActionType.CREATE_RECORD,
|
||||
valid: false,
|
||||
settings: {
|
||||
...BASE_STEP_DEFINITION,
|
||||
input: {
|
||||
type: WorkflowRecordCRUDType.CREATE,
|
||||
objectName: activeObjectMetadataItem?.nameSingular || '',
|
||||
objectRecord: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
case `${WorkflowActionType.RECORD_CRUD}.${WorkflowRecordCRUDType.UPDATE}`: {
|
||||
case WorkflowActionType.UPDATE_RECORD: {
|
||||
const activeObjectMetadataItem =
|
||||
await this.objectMetadataRepository.findOne({
|
||||
where: { workspaceId, isActive: true, isSystem: false },
|
||||
@ -156,12 +154,11 @@ export class WorkflowVersionStepWorkspaceService {
|
||||
return {
|
||||
id: newStepId,
|
||||
name: 'Update Record',
|
||||
type: WorkflowActionType.RECORD_CRUD,
|
||||
type: WorkflowActionType.UPDATE_RECORD,
|
||||
valid: false,
|
||||
settings: {
|
||||
...BASE_STEP_DEFINITION,
|
||||
input: {
|
||||
type: WorkflowRecordCRUDType.UPDATE,
|
||||
objectName: activeObjectMetadataItem?.nameSingular || '',
|
||||
objectRecord: {},
|
||||
objectRecordId: '',
|
||||
@ -169,7 +166,7 @@ export class WorkflowVersionStepWorkspaceService {
|
||||
},
|
||||
};
|
||||
}
|
||||
case `${WorkflowActionType.RECORD_CRUD}.${WorkflowRecordCRUDType.DELETE}`: {
|
||||
case WorkflowActionType.DELETE_RECORD: {
|
||||
const activeObjectMetadataItem =
|
||||
await this.objectMetadataRepository.findOne({
|
||||
where: { workspaceId, isActive: true, isSystem: false },
|
||||
@ -178,12 +175,11 @@ export class WorkflowVersionStepWorkspaceService {
|
||||
return {
|
||||
id: newStepId,
|
||||
name: 'Delete Record',
|
||||
type: WorkflowActionType.RECORD_CRUD,
|
||||
type: WorkflowActionType.DELETE_RECORD,
|
||||
valid: false,
|
||||
settings: {
|
||||
...BASE_STEP_DEFINITION,
|
||||
input: {
|
||||
type: WorkflowRecordCRUDType.DELETE,
|
||||
objectName: activeObjectMetadataItem?.nameSingular || '',
|
||||
objectRecordId: '',
|
||||
},
|
||||
|
@ -20,7 +20,6 @@ import {
|
||||
} from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { generateFakeObjectRecord } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record';
|
||||
import { generateFakeObjectRecordEvent } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record-event';
|
||||
import { WorkflowRecordCRUDType } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowActionType,
|
||||
@ -85,10 +84,17 @@ export class WorkflowBuilderWorkspaceService {
|
||||
codeIntrospectionService: this.codeIntrospectionService,
|
||||
});
|
||||
}
|
||||
case WorkflowActionType.RECORD_CRUD:
|
||||
return this.computeRecordCrudOutputSchema({
|
||||
case WorkflowActionType.CREATE_RECORD:
|
||||
case WorkflowActionType.UPDATE_RECORD:
|
||||
case WorkflowActionType.DELETE_RECORD:
|
||||
return this.computeRecordOutputSchema({
|
||||
objectType: step.settings.input.objectName,
|
||||
workspaceId,
|
||||
objectMetadataRepository: this.objectMetadataRepository,
|
||||
});
|
||||
case WorkflowActionType.FIND_RECORDS:
|
||||
return this.computeFindRecordsOutputSchema({
|
||||
objectType: step.settings.input.objectName,
|
||||
operationType: step.settings.input.type,
|
||||
workspaceId,
|
||||
objectMetadataRepository: this.objectMetadataRepository,
|
||||
});
|
||||
@ -130,14 +136,12 @@ export class WorkflowBuilderWorkspaceService {
|
||||
);
|
||||
}
|
||||
|
||||
private async computeRecordCrudOutputSchema({
|
||||
private async computeFindRecordsOutputSchema({
|
||||
objectType,
|
||||
operationType,
|
||||
workspaceId,
|
||||
objectMetadataRepository,
|
||||
}: {
|
||||
objectType: string;
|
||||
operationType: string;
|
||||
workspaceId: string;
|
||||
objectMetadataRepository: Repository<ObjectMetadataEntity>;
|
||||
}): Promise<OutputSchema> {
|
||||
@ -147,24 +151,20 @@ export class WorkflowBuilderWorkspaceService {
|
||||
objectMetadataRepository,
|
||||
});
|
||||
|
||||
if (operationType === WorkflowRecordCRUDType.READ) {
|
||||
return {
|
||||
first: {
|
||||
isLeaf: false,
|
||||
icon: 'IconAlpha',
|
||||
value: recordOutputSchema,
|
||||
},
|
||||
last: { isLeaf: false, icon: 'IconOmega', value: recordOutputSchema },
|
||||
totalCount: {
|
||||
isLeaf: true,
|
||||
icon: 'IconSum',
|
||||
type: 'number',
|
||||
value: generateFakeValue('number'),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return recordOutputSchema;
|
||||
return {
|
||||
first: {
|
||||
isLeaf: false,
|
||||
icon: 'IconAlpha',
|
||||
value: recordOutputSchema,
|
||||
},
|
||||
last: { isLeaf: false, icon: 'IconOmega', value: recordOutputSchema },
|
||||
totalCount: {
|
||||
isLeaf: true,
|
||||
icon: 'IconSum',
|
||||
type: 'number',
|
||||
value: generateFakeValue('number'),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async computeRecordOutputSchema({
|
||||
|
@ -8,7 +8,10 @@ import {
|
||||
} 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 { SendEmailWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/send-email.workflow-action';
|
||||
import { RecordCRUDWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/record-crud.workflow-action';
|
||||
import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action';
|
||||
import { DeleteRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/delete-record.workflow-action';
|
||||
import { FindRecordsWorflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/find-records.workflow-action';
|
||||
import { UpdateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/update-record.workflow-action';
|
||||
import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
||||
|
||||
@Injectable()
|
||||
@ -16,7 +19,10 @@ export class WorkflowActionFactory {
|
||||
constructor(
|
||||
private readonly codeWorkflowAction: CodeWorkflowAction,
|
||||
private readonly sendEmailWorkflowAction: SendEmailWorkflowAction,
|
||||
private readonly recordCRUDWorkflowAction: RecordCRUDWorkflowAction,
|
||||
private readonly createRecordWorkflowAction: CreateRecordWorkflowAction,
|
||||
private readonly updateRecordWorkflowAction: UpdateRecordWorkflowAction,
|
||||
private readonly deleteRecordWorkflowAction: DeleteRecordWorkflowAction,
|
||||
private readonly findRecordsWorflowAction: FindRecordsWorflowAction,
|
||||
) {}
|
||||
|
||||
get(stepType: WorkflowActionType): WorkflowAction {
|
||||
@ -25,8 +31,14 @@ export class WorkflowActionFactory {
|
||||
return this.codeWorkflowAction;
|
||||
case WorkflowActionType.SEND_EMAIL:
|
||||
return this.sendEmailWorkflowAction;
|
||||
case WorkflowActionType.RECORD_CRUD:
|
||||
return this.recordCRUDWorkflowAction;
|
||||
case WorkflowActionType.CREATE_RECORD:
|
||||
return this.createRecordWorkflowAction;
|
||||
case WorkflowActionType.UPDATE_RECORD:
|
||||
return this.updateRecordWorkflowAction;
|
||||
case WorkflowActionType.DELETE_RECORD:
|
||||
return this.deleteRecordWorkflowAction;
|
||||
case WorkflowActionType.FIND_RECORDS:
|
||||
return this.findRecordsWorflowAction;
|
||||
default:
|
||||
throw new WorkflowStepExecutorException(
|
||||
`Workflow step executor not found for step type '${stepType}'`,
|
||||
|
@ -0,0 +1,30 @@
|
||||
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/record-crud/types/workflow-record-crud-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: WorkflowCreateRecordActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
);
|
||||
|
||||
const objectRecord = await repository.create(
|
||||
workflowActionInput.objectRecord,
|
||||
);
|
||||
|
||||
await repository.save(objectRecord);
|
||||
|
||||
return {
|
||||
result: objectRecord,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
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 {
|
||||
RecordCRUDActionException,
|
||||
RecordCRUDActionExceptionCode,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/exceptions/record-crud-action.exception';
|
||||
import { WorkflowDeleteRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-result.type';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteRecordWorkflowAction implements WorkflowAction {
|
||||
constructor(private readonly twentyORMManager: TwentyORMManager) {}
|
||||
|
||||
async execute(
|
||||
workflowActionInput: WorkflowDeleteRecordActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
);
|
||||
|
||||
const objectRecord = await repository.findOne({
|
||||
where: {
|
||||
id: workflowActionInput.objectRecordId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!objectRecord) {
|
||||
throw new RecordCRUDActionException(
|
||||
`Failed to delete: Record ${workflowActionInput.objectName} with id ${workflowActionInput.objectRecordId} not found`,
|
||||
RecordCRUDActionExceptionCode.RECORD_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
await repository.update(workflowActionInput.objectRecordId, {
|
||||
deletedAt: new Date(),
|
||||
});
|
||||
|
||||
return {
|
||||
result: objectRecord,
|
||||
};
|
||||
}
|
||||
}
|
@ -24,18 +24,11 @@ import {
|
||||
RecordCRUDActionException,
|
||||
RecordCRUDActionExceptionCode,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/exceptions/record-crud-action.exception';
|
||||
import {
|
||||
WorkflowCreateRecordActionInput,
|
||||
WorkflowDeleteRecordActionInput,
|
||||
WorkflowReadRecordActionInput,
|
||||
WorkflowRecordCRUDActionInput,
|
||||
WorkflowRecordCRUDType,
|
||||
WorkflowUpdateRecordActionInput,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import { WorkflowFindRecordsActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-result.type';
|
||||
|
||||
@Injectable()
|
||||
export class RecordCRUDWorkflowAction implements WorkflowAction {
|
||||
export class FindRecordsWorflowAction implements WorkflowAction {
|
||||
constructor(
|
||||
private readonly twentyORMManager: TwentyORMManager,
|
||||
private readonly workspaceCacheStorageService: WorkspaceCacheStorageService,
|
||||
@ -43,106 +36,7 @@ export class RecordCRUDWorkflowAction implements WorkflowAction {
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
workflowActionInput: WorkflowRecordCRUDActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
switch (workflowActionInput.type) {
|
||||
case WorkflowRecordCRUDType.CREATE:
|
||||
return this.createRecord(workflowActionInput);
|
||||
case WorkflowRecordCRUDType.DELETE:
|
||||
return this.deleteRecord(workflowActionInput);
|
||||
case WorkflowRecordCRUDType.UPDATE:
|
||||
return this.updateRecord(workflowActionInput);
|
||||
case WorkflowRecordCRUDType.READ:
|
||||
return this.findRecords(workflowActionInput);
|
||||
default:
|
||||
throw new RecordCRUDActionException(
|
||||
`Unknown record operation type`,
|
||||
RecordCRUDActionExceptionCode.INVALID_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async createRecord(
|
||||
workflowActionInput: WorkflowCreateRecordActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
);
|
||||
|
||||
const objectRecord = await repository.create(
|
||||
workflowActionInput.objectRecord,
|
||||
);
|
||||
|
||||
await repository.save(objectRecord);
|
||||
|
||||
return {
|
||||
result: objectRecord,
|
||||
};
|
||||
}
|
||||
|
||||
private async updateRecord(
|
||||
workflowActionInput: WorkflowUpdateRecordActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
);
|
||||
|
||||
const objectRecord = await repository.findOne({
|
||||
where: {
|
||||
id: workflowActionInput.objectRecordId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!objectRecord) {
|
||||
throw new RecordCRUDActionException(
|
||||
`Failed to update: Record ${workflowActionInput.objectName} with id ${workflowActionInput.objectRecordId} not found`,
|
||||
RecordCRUDActionExceptionCode.RECORD_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
await repository.update(workflowActionInput.objectRecordId, {
|
||||
...workflowActionInput.objectRecord,
|
||||
});
|
||||
|
||||
return {
|
||||
result: {
|
||||
...objectRecord,
|
||||
...workflowActionInput.objectRecord,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async deleteRecord(
|
||||
workflowActionInput: WorkflowDeleteRecordActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
);
|
||||
|
||||
const objectRecord = await repository.findOne({
|
||||
where: {
|
||||
id: workflowActionInput.objectRecordId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!objectRecord) {
|
||||
throw new RecordCRUDActionException(
|
||||
`Failed to delete: Record ${workflowActionInput.objectName} with id ${workflowActionInput.objectRecordId} not found`,
|
||||
RecordCRUDActionExceptionCode.RECORD_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
await repository.update(workflowActionInput.objectRecordId, {
|
||||
deletedAt: new Date(),
|
||||
});
|
||||
|
||||
return {
|
||||
result: objectRecord,
|
||||
};
|
||||
}
|
||||
|
||||
private async findRecords(
|
||||
workflowActionInput: WorkflowReadRecordActionInput,
|
||||
workflowActionInput: WorkflowFindRecordsActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
@ -221,7 +115,7 @@ export class RecordCRUDWorkflowAction implements WorkflowAction {
|
||||
}
|
||||
|
||||
private async getObjectRecords<T extends ObjectLiteral>(
|
||||
workflowActionInput: WorkflowReadRecordActionInput,
|
||||
workflowActionInput: WorkflowFindRecordsActionInput,
|
||||
objectMetadataItemWithFieldsMaps: ObjectMetadataItemWithFieldMaps,
|
||||
objectMetadataMaps: ObjectMetadataMaps,
|
||||
repository: WorkspaceRepository<T>,
|
||||
@ -261,7 +155,7 @@ export class RecordCRUDWorkflowAction implements WorkflowAction {
|
||||
}
|
||||
|
||||
private async getTotalCount(
|
||||
workflowActionInput: WorkflowReadRecordActionInput,
|
||||
workflowActionInput: WorkflowFindRecordsActionInput,
|
||||
repository: WorkspaceRepository<Entity>,
|
||||
graphqlQueryParser: GraphqlQueryParser,
|
||||
) {
|
@ -2,11 +2,25 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
||||
import { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/workspace-cache-storage.module';
|
||||
import { RecordCRUDWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/record-crud.workflow-action';
|
||||
import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action';
|
||||
import { DeleteRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/delete-record.workflow-action';
|
||||
import { FindRecordsWorflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/find-records.workflow-action';
|
||||
import { UpdateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/update-record.workflow-action';
|
||||
|
||||
@Module({
|
||||
imports: [WorkspaceCacheStorageModule],
|
||||
providers: [RecordCRUDWorkflowAction, ScopedWorkspaceContextFactory],
|
||||
exports: [RecordCRUDWorkflowAction],
|
||||
providers: [
|
||||
ScopedWorkspaceContextFactory,
|
||||
CreateRecordWorkflowAction,
|
||||
UpdateRecordWorkflowAction,
|
||||
DeleteRecordWorkflowAction,
|
||||
FindRecordsWorflowAction,
|
||||
],
|
||||
exports: [
|
||||
CreateRecordWorkflowAction,
|
||||
UpdateRecordWorkflowAction,
|
||||
DeleteRecordWorkflowAction,
|
||||
FindRecordsWorflowAction,
|
||||
],
|
||||
})
|
||||
export class RecordCRUDActionModule {}
|
||||
|
@ -5,42 +5,25 @@ import {
|
||||
|
||||
type ObjectRecord = Record<string, any>;
|
||||
|
||||
export enum WorkflowRecordCRUDType {
|
||||
CREATE = 'CREATE',
|
||||
UPDATE = 'UPDATE',
|
||||
DELETE = 'DELETE',
|
||||
READ = 'READ',
|
||||
}
|
||||
|
||||
export type WorkflowCreateRecordActionInput = {
|
||||
type: WorkflowRecordCRUDType.CREATE;
|
||||
objectName: string;
|
||||
objectRecord: ObjectRecord;
|
||||
};
|
||||
|
||||
export type WorkflowUpdateRecordActionInput = {
|
||||
type: WorkflowRecordCRUDType.UPDATE;
|
||||
objectName: string;
|
||||
objectRecord: ObjectRecord;
|
||||
objectRecordId: string;
|
||||
};
|
||||
|
||||
export type WorkflowDeleteRecordActionInput = {
|
||||
type: WorkflowRecordCRUDType.DELETE;
|
||||
objectName: string;
|
||||
objectRecordId: string;
|
||||
};
|
||||
|
||||
export type WorkflowReadRecordActionInput = {
|
||||
type: WorkflowRecordCRUDType.READ;
|
||||
export type WorkflowFindRecordsActionInput = {
|
||||
objectName: string;
|
||||
filter?: Partial<ObjectRecordFilter>;
|
||||
orderBy?: Partial<ObjectRecordOrderBy>;
|
||||
limit?: number;
|
||||
};
|
||||
|
||||
export type WorkflowRecordCRUDActionInput =
|
||||
| WorkflowCreateRecordActionInput
|
||||
| WorkflowUpdateRecordActionInput
|
||||
| WorkflowDeleteRecordActionInput
|
||||
| WorkflowReadRecordActionInput;
|
||||
|
@ -1,6 +1,23 @@
|
||||
import { WorkflowRecordCRUDActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import {
|
||||
WorkflowCreateRecordActionInput,
|
||||
WorkflowDeleteRecordActionInput,
|
||||
WorkflowFindRecordsActionInput,
|
||||
WorkflowUpdateRecordActionInput,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type';
|
||||
|
||||
export type WorkflowRecordCRUDActionSettings = BaseWorkflowActionSettings & {
|
||||
input: WorkflowRecordCRUDActionInput;
|
||||
export type WorkflowCreateRecordActionSettings = BaseWorkflowActionSettings & {
|
||||
input: WorkflowCreateRecordActionInput;
|
||||
};
|
||||
|
||||
export type WorkflowUpdateRecordActionSettings = BaseWorkflowActionSettings & {
|
||||
input: WorkflowUpdateRecordActionInput;
|
||||
};
|
||||
|
||||
export type WorkflowDeleteRecordActionSettings = BaseWorkflowActionSettings & {
|
||||
input: WorkflowDeleteRecordActionInput;
|
||||
};
|
||||
|
||||
export type WorkflowFindRecordsActionSettings = BaseWorkflowActionSettings & {
|
||||
input: WorkflowFindRecordsActionInput;
|
||||
};
|
||||
|
@ -0,0 +1,48 @@
|
||||
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 {
|
||||
RecordCRUDActionException,
|
||||
RecordCRUDActionExceptionCode,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/exceptions/record-crud-action.exception';
|
||||
import { WorkflowUpdateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';
|
||||
import { WorkflowActionResult } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-result.type';
|
||||
|
||||
@Injectable()
|
||||
export class UpdateRecordWorkflowAction implements WorkflowAction {
|
||||
constructor(private readonly twentyORMManager: TwentyORMManager) {}
|
||||
|
||||
async execute(
|
||||
workflowActionInput: WorkflowUpdateRecordActionInput,
|
||||
): Promise<WorkflowActionResult> {
|
||||
const repository = await this.twentyORMManager.getRepository(
|
||||
workflowActionInput.objectName,
|
||||
);
|
||||
|
||||
const objectRecord = await repository.findOne({
|
||||
where: {
|
||||
id: workflowActionInput.objectRecordId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!objectRecord) {
|
||||
throw new RecordCRUDActionException(
|
||||
`Failed to update: Record ${workflowActionInput.objectName} with id ${workflowActionInput.objectRecordId} not found`,
|
||||
RecordCRUDActionExceptionCode.RECORD_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
await repository.update(workflowActionInput.objectRecordId, {
|
||||
...workflowActionInput.objectRecord,
|
||||
});
|
||||
|
||||
return {
|
||||
result: {
|
||||
...objectRecord,
|
||||
...workflowActionInput.objectRecord,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
import { OutputSchema } from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import { WorkflowCodeActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/code/types/workflow-code-action-settings.type';
|
||||
import { WorkflowSendEmailActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/types/workflow-send-email-action-settings.type';
|
||||
import { WorkflowRecordCRUDActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-settings.type';
|
||||
import { OutputSchema } from 'src/modules/workflow/workflow-builder/types/output-schema.type';
|
||||
import {
|
||||
WorkflowCreateRecordActionSettings,
|
||||
WorkflowDeleteRecordActionSettings,
|
||||
WorkflowFindRecordsActionSettings,
|
||||
WorkflowUpdateRecordActionSettings,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-settings.type';
|
||||
|
||||
export type BaseWorkflowActionSettings = {
|
||||
input: object;
|
||||
@ -19,4 +24,7 @@ export type BaseWorkflowActionSettings = {
|
||||
export type WorkflowActionSettings =
|
||||
| WorkflowSendEmailActionSettings
|
||||
| WorkflowCodeActionSettings
|
||||
| WorkflowRecordCRUDActionSettings;
|
||||
| WorkflowCreateRecordActionSettings
|
||||
| WorkflowUpdateRecordActionSettings
|
||||
| WorkflowDeleteRecordActionSettings
|
||||
| WorkflowFindRecordsActionSettings;
|
||||
|
@ -1,12 +1,20 @@
|
||||
import { WorkflowCodeActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/code/types/workflow-code-action-settings.type';
|
||||
import { WorkflowSendEmailActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/types/workflow-send-email-action-settings.type';
|
||||
import { WorkflowRecordCRUDActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-settings.type';
|
||||
import {
|
||||
WorkflowCreateRecordActionSettings,
|
||||
WorkflowDeleteRecordActionSettings,
|
||||
WorkflowFindRecordsActionSettings,
|
||||
WorkflowUpdateRecordActionSettings,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-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',
|
||||
RECORD_CRUD = 'RECORD_CRUD',
|
||||
CREATE_RECORD = 'CREATE_RECORD',
|
||||
UPDATE_RECORD = 'UPDATE_RECORD',
|
||||
DELETE_RECORD = 'DELETE_RECORD',
|
||||
FIND_RECORDS = 'FIND_RECORDS',
|
||||
}
|
||||
|
||||
type BaseWorkflowAction = {
|
||||
@ -27,12 +35,30 @@ export type WorkflowSendEmailAction = BaseWorkflowAction & {
|
||||
settings: WorkflowSendEmailActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowRecordCRUDAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.RECORD_CRUD;
|
||||
settings: WorkflowRecordCRUDActionSettings;
|
||||
export type WorkflowCreateRecordAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.CREATE_RECORD;
|
||||
settings: WorkflowCreateRecordActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowUpdateRecordAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.UPDATE_RECORD;
|
||||
settings: WorkflowUpdateRecordActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowDeleteRecordAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.DELETE_RECORD;
|
||||
settings: WorkflowDeleteRecordActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowFindRecordsAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.FIND_RECORDS;
|
||||
settings: WorkflowFindRecordsActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowAction =
|
||||
| WorkflowCodeAction
|
||||
| WorkflowSendEmailAction
|
||||
| WorkflowRecordCRUDAction;
|
||||
| WorkflowCreateRecordAction
|
||||
| WorkflowUpdateRecordAction
|
||||
| WorkflowDeleteRecordAction
|
||||
| WorkflowFindRecordsAction;
|
||||
|
Loading…
Reference in New Issue
Block a user