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 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();
}
}