Create automation
This commit is contained in:
parent
6571d61b86
commit
faf1d678fa
|
@ -2,10 +2,16 @@ import { context, HTTPError, utils } from "@budibase/backend-core"
|
||||||
|
|
||||||
import { generateRowActionsID } from "../../db/utils"
|
import { generateRowActionsID } from "../../db/utils"
|
||||||
import {
|
import {
|
||||||
|
AutomationCustomIOType,
|
||||||
|
AutomationIOType,
|
||||||
|
AutomationStepType,
|
||||||
|
AutomationTriggerStepId,
|
||||||
SEPARATOR,
|
SEPARATOR,
|
||||||
TableRowActions,
|
TableRowActions,
|
||||||
VirtualDocumentType,
|
VirtualDocumentType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import automations from "./automations"
|
||||||
|
import tables from "./tables"
|
||||||
|
|
||||||
function ensureUniqueAndThrow(
|
function ensureUniqueAndThrow(
|
||||||
doc: TableRowActions,
|
doc: TableRowActions,
|
||||||
|
@ -39,10 +45,48 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
doc = { _id: rowActionsId, actions: {} }
|
doc = { _id: rowActionsId, actions: {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { name: tableName } = await tables.getTable(tableId)
|
||||||
|
|
||||||
ensureUniqueAndThrow(doc, action.name)
|
ensureUniqueAndThrow(doc, action.name)
|
||||||
|
|
||||||
|
const automation = await automations.create({
|
||||||
|
name: `${tableName}: ${action.name}`,
|
||||||
|
appId: context.getAppId()!,
|
||||||
|
definition: {
|
||||||
|
trigger: {
|
||||||
|
type: AutomationStepType.TRIGGER,
|
||||||
|
id: "TODO id",
|
||||||
|
tagline: "TODO tagline",
|
||||||
|
name: "Row Action",
|
||||||
|
description: "TODO description",
|
||||||
|
icon: "Workflow",
|
||||||
|
stepId: AutomationTriggerStepId.ROW_ACTION,
|
||||||
|
inputs: {
|
||||||
|
tableId,
|
||||||
|
},
|
||||||
|
schema: {
|
||||||
|
inputs: {
|
||||||
|
properties: {
|
||||||
|
tableId: {
|
||||||
|
type: AutomationIOType.STRING,
|
||||||
|
customType: AutomationCustomIOType.TABLE,
|
||||||
|
title: "Table",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["tableId"],
|
||||||
|
},
|
||||||
|
outputs: { properties: {} },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
steps: [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
|
const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
|
||||||
doc.actions[newId] = action
|
doc.actions[newId] = {
|
||||||
|
name: action.name,
|
||||||
|
automationId: automation._id!,
|
||||||
|
}
|
||||||
await db.put(doc)
|
await db.put(doc)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -45,6 +45,7 @@ export enum AutomationTriggerStepId {
|
||||||
WEBHOOK = "WEBHOOK",
|
WEBHOOK = "WEBHOOK",
|
||||||
APP = "APP",
|
APP = "APP",
|
||||||
CRON = "CRON",
|
CRON = "CRON",
|
||||||
|
ROW_ACTION = "ROW_ACTION",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AutomationStepType {
|
export enum AutomationStepType {
|
||||||
|
|
Loading…
Reference in New Issue