From d7a3142adaca2b44309679234b11a1c8da2a0110 Mon Sep 17 00:00:00 2001 From: sealday Date: Wed, 12 Jun 2024 14:24:18 +0800 Subject: [PATCH] fix: submit to workflow error (#1163) fix #1162 Co-authored-by: sealday Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1163 --- .../src/server/actions/workflows.ts | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/actions/workflows.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/actions/workflows.ts index 924b28817..cd2553bbd 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/actions/workflows.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/actions/workflows.ts @@ -1,4 +1,4 @@ -import actions, { Context, utils } from '@tachybase/actions'; +import actions, { Context, Next, utils } from '@tachybase/actions'; import { Op, Repository } from '@tachybase/database'; import Plugin from '../Plugin'; @@ -161,21 +161,25 @@ export async function sync(context: Context, next) { await next(); } -export async function trigger(ctx: Context) { - const plugin = ctx.app.getPlugin(Plugin) as Plugin; - const workflow = (await ctx.db.getRepository('workflows').findById(ctx.action.params.filterByTk)) as WorkflowModel; - // NOTE: 这里的updateData是通过前端传过来的,需要 decodeURIComponent, - // updateData 的约定结构是形如: updateData: { primaryKey: "id", targetKeys: []} - const updateData = JSON.parse(decodeURIComponent(ctx.action.params?.updateData || '')); - plugin.trigger( - workflow, - { - data: { - updateData, - httpContext: ctx, - user: ctx?.auth?.user, +export async function trigger(ctx: Context, next: Next) { + if (!ctx.action.params.triggerWorkflows) { + const plugin = ctx.app.getPlugin(Plugin) as Plugin; + const workflow = (await ctx.db.getRepository('workflows').findById(ctx.action.params.filterByTk)) as WorkflowModel; + // NOTE: 这里的updateData是通过前端传过来的,需要 decodeURIComponent, + // updateData 的约定结构是形如: updateData: { primaryKey: "id", targetKeys: []} + const updateData = JSON.parse(decodeURIComponent(ctx.action.params?.updateData || '')); + plugin.trigger( + workflow, + { + data: { + updateData, + httpContext: ctx, + user: ctx?.auth?.user, + }, }, - }, - { httpContext: ctx }, - ); + { httpContext: ctx }, + ); + } else { + await next(); + } }