-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create record action #8460
Create record action #8460
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The WorkflowActionType enum only contained CODE and SEND_EMAIL, but the PR adds CREATE_RECORD. Make sure the new enum location includes all three action types. |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { ServerlessFunctionModule } from 'src/engine/metadata-modules/serverless-function/serverless-function.module'; | ||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory'; | ||
import { CodeWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/code/code.workflow-action'; | ||
|
||
@Module({ | ||
imports: [ServerlessFunctionModule], | ||
providers: [ScopedWorkspaceContextFactory, CodeWorkflowAction], | ||
exports: [CodeWorkflowAction], | ||
}) | ||
export class CodeActionModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type WorkflowCodeActionInput = { | ||
serverlessFunctionId: string; | ||
serverlessFunctionVersion: string; | ||
serverlessFunctionInput: { | ||
[key: string]: any; | ||
}; | ||
thomtrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { WorkflowCodeActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/code/types/workflow-code-action-input.type'; | ||
import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type'; | ||
|
||
export type WorkflowCodeActionSettings = BaseWorkflowActionSettings & { | ||
input: WorkflowCodeActionInput; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/create-record.workflow-action'; | ||
|
||
@Module({ | ||
providers: [CreateRecordWorkflowAction], | ||
exports: [CreateRecordWorkflowAction], | ||
}) | ||
export class CreateRecordActionModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 { 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> { | ||
thomtrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const repository = await this.twentyORMManager.getRepository( | ||
workflowActionInput.objectName, | ||
); | ||
|
||
const objectRecord = await repository.create( | ||
workflowActionInput.objectRecord, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: No validation of workflowActionInput.objectRecord before creation. Could allow invalid/malicious data. |
||
|
||
const createdObjectRecord = await repository.save(objectRecord); | ||
|
||
return { result: createdObjectRecord }; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type ObjectRecord = Record<string, any>; | ||
|
||
export type WorkflowCreateRecordActionInput = { | ||
objectName: string; | ||
objectRecord: ObjectRecord; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { WorkflowCreateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/create-record/types/workflow-create-record-action-input.type'; | ||
import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type'; | ||
|
||
export type WorkflowCreateRecordActionSettings = BaseWorkflowActionSettings & { | ||
input: WorkflowCreateRecordActionInput; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Missing outputSchema override from BaseWorkflowActionSettings. Should define the shape of created record output. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { CustomException } from 'src/utils/custom-exception'; | ||
|
||
export class MailSenderException extends CustomException { | ||
code: MailSenderExceptionCode; | ||
constructor(message: string, code: MailSenderExceptionCode) { | ||
export class SendEmailActionException extends CustomException { | ||
code: SendEmailActionExceptionCode; | ||
constructor(message: string, code: SendEmailActionExceptionCode) { | ||
super(message, code); | ||
} | ||
} | ||
|
||
export enum MailSenderExceptionCode { | ||
export enum SendEmailActionExceptionCode { | ||
PROVIDER_NOT_SUPPORTED = 'PROVIDER_NOT_SUPPORTED', | ||
CONNECTED_ACCOUNT_NOT_FOUND = 'CONNECTED_ACCOUNT_NOT_FOUND', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory'; | ||
import { OAuth2ClientManagerModule } from 'src/modules/connected-account/oauth2-client-manager/oauth2-client-manager.module'; | ||
import { GmailClientProvider } from 'src/modules/messaging/message-import-manager/drivers/gmail/providers/gmail-client.provider'; | ||
import { SendEmailWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/send-email.workflow-action'; | ||
|
||
@Module({ | ||
imports: [OAuth2ClientManagerModule], | ||
providers: [ | ||
GmailClientProvider, | ||
ScopedWorkspaceContextFactory, | ||
SendEmailWorkflowAction, | ||
], | ||
exports: [SendEmailWorkflowAction], | ||
}) | ||
export class SendEmailActionModule {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think it worth renaming
steps
intoactions
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think branches, conditions, loops will be actions. There would be better as steps. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed