fix: submit to workflow error (#1163) fix #1162

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachybase#1163
This commit is contained in:
sealday 2024-06-12 14:24:18 +08:00
parent c15e594855
commit d7a3142ada

View File

@ -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 { Op, Repository } from '@tachybase/database';
import Plugin from '../Plugin'; import Plugin from '../Plugin';
@ -161,21 +161,25 @@ export async function sync(context: Context, next) {
await next(); await next();
} }
export async function trigger(ctx: Context) { export async function trigger(ctx: Context, next: Next) {
const plugin = ctx.app.getPlugin(Plugin) as Plugin; if (!ctx.action.params.triggerWorkflows) {
const workflow = (await ctx.db.getRepository('workflows').findById(ctx.action.params.filterByTk)) as WorkflowModel; const plugin = ctx.app.getPlugin(Plugin) as Plugin;
// NOTE: 这里的updateData是通过前端传过来的需要 decodeURIComponent, const workflow = (await ctx.db.getRepository('workflows').findById(ctx.action.params.filterByTk)) as WorkflowModel;
// updateData 的约定结构是形如: updateData: { primaryKey: "id", targetKeys: []} // NOTE: 这里的updateData是通过前端传过来的需要 decodeURIComponent,
const updateData = JSON.parse(decodeURIComponent(ctx.action.params?.updateData || '')); // updateData 的约定结构是形如: updateData: { primaryKey: "id", targetKeys: []}
plugin.trigger( const updateData = JSON.parse(decodeURIComponent(ctx.action.params?.updateData || ''));
workflow, plugin.trigger(
{ workflow,
data: { {
updateData, data: {
httpContext: ctx, updateData,
user: ctx?.auth?.user, httpContext: ctx,
user: ctx?.auth?.user,
},
}, },
}, { httpContext: ctx },
{ httpContext: ctx }, );
); } else {
await next();
}
} }