Implement run
This commit is contained in:
parent
890d573cac
commit
f7a460a1ea
|
@ -2,13 +2,9 @@ import { RowActionTriggerRequest, Ctx } from "@budibase/types"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
|
|
||||||
export async function run(ctx: Ctx<RowActionTriggerRequest, void>) {
|
export async function run(ctx: Ctx<RowActionTriggerRequest, void>) {
|
||||||
const { tableId } = ctx.params
|
const { tableId, actionId } = ctx.params
|
||||||
const table = await sdk.tables.getTable(tableId)
|
|
||||||
if (!table) {
|
|
||||||
ctx.throw(404)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { rowId } = ctx.request.body
|
const { rowId } = ctx.request.body
|
||||||
console.warn({ rowId })
|
|
||||||
|
await sdk.rowActions.run(tableId, actionId, rowId)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,7 @@ function rowPassesFilters(row: Row, filters: SearchFilters) {
|
||||||
|
|
||||||
export async function externalTrigger(
|
export async function externalTrigger(
|
||||||
automation: Automation,
|
automation: Automation,
|
||||||
params: { fields: Record<string, any>; timeout?: number },
|
params: { fields: Record<string, any>; timeout?: number; appId?: string },
|
||||||
{ getResponses }: { getResponses?: boolean } = {}
|
{ getResponses }: { getResponses?: boolean } = {}
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
if (automation.disabled) {
|
if (automation.disabled) {
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import { context, HTTPError, utils } from "@budibase/backend-core"
|
import { context, HTTPError, utils } from "@budibase/backend-core"
|
||||||
|
|
||||||
import { generateRowActionsID } from "../../db/utils"
|
|
||||||
import {
|
import {
|
||||||
SEPARATOR,
|
SEPARATOR,
|
||||||
TableRowActions,
|
TableRowActions,
|
||||||
VirtualDocumentType,
|
VirtualDocumentType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import { generateRowActionsID } from "../../db/utils"
|
||||||
import automations from "./automations"
|
import automations from "./automations"
|
||||||
import { definitions as TRIGGER_DEFINITIONS } from "../../automations/triggerInfo"
|
import { definitions as TRIGGER_DEFINITIONS } from "../../automations/triggerInfo"
|
||||||
|
import * as triggers from "../../automations/triggers"
|
||||||
|
import sdk from ".."
|
||||||
|
|
||||||
function ensureUniqueAndThrow(
|
function ensureUniqueAndThrow(
|
||||||
doc: TableRowActions,
|
doc: TableRowActions,
|
||||||
|
@ -143,3 +145,25 @@ export async function remove(tableId: string, rowActionId: string) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
await db.put(actionsDoc)
|
await db.put(actionsDoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function run(tableId: any, rowActionId: any, rowId: string) {
|
||||||
|
const table = await sdk.tables.getTable(tableId)
|
||||||
|
if (!table) {
|
||||||
|
throw new HTTPError("Table not found", 404)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { actions } = await get(tableId)
|
||||||
|
|
||||||
|
const rowAction = actions[rowActionId]
|
||||||
|
if (!rowAction) {
|
||||||
|
throw new HTTPError("Row action not found", 404)
|
||||||
|
}
|
||||||
|
|
||||||
|
const automation = await sdk.automations.get(rowAction.automationId)
|
||||||
|
|
||||||
|
const row = await sdk.rows.find(tableId, rowId)
|
||||||
|
await triggers.externalTrigger(automation, {
|
||||||
|
fields: { row, table },
|
||||||
|
appId: context.getAppId(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue