fix(plugin-workflow): fix toJSON type check (#2772)

* fix(plugin-workflow): fix toJSON type check

* fix(plugin-workflow): fix type check logic order
This commit is contained in:
Junyi 2023-10-09 17:48:20 +08:00 committed by GitHub
parent 1defb5db51
commit f280dcfb00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -33,7 +33,14 @@ export default class FormTrigger extends Trigger {
middleware = async (context, next) => { middleware = async (context, next) => {
await next(); await next();
const { resourceName, actionName } = context.action; const {
resourceName,
actionName,
params: { triggerWorkflows },
} = context.action;
if (!triggerWorkflows) {
return;
}
if ((resourceName === 'workflows' && actionName === 'trigger') || !['create', 'update'].includes(actionName)) { if ((resourceName === 'workflows' && actionName === 'trigger') || !['create', 'update'].includes(actionName)) {
return; return;
@ -42,11 +49,8 @@ export default class FormTrigger extends Trigger {
this.trigger(context); this.trigger(context);
}; };
async trigger(context) { private async trigger(context) {
const { triggerWorkflows, values } = context.action.params; const { triggerWorkflows = '', values } = context.action.params;
if (!triggerWorkflows) {
return;
}
const { currentUser } = context.state; const { currentUser } = context.state;

View File

@ -1,15 +1,15 @@
import { Model } from '@nocobase/database'; import { Model } from '@nocobase/database';
export function toJSON(data: Model | Model[]): object { export function toJSON(data: Model | Model[]): object {
if (typeof data !== 'object' || !data) {
return data;
}
if (Array.isArray(data)) { if (Array.isArray(data)) {
return data.map(toJSON); return data.map(toJSON);
} }
if (!(data instanceof Model) || !data) {
return data;
}
const result = data.get(); const result = data.get();
Object.keys((<typeof Model>data.constructor).associations).forEach((key) => { Object.keys((<typeof Model>data.constructor).associations).forEach((key) => {
if (result[key] != null) { if (result[key] != null && typeof result[key] === 'object') {
result[key] = toJSON(result[key]); result[key] = toJSON(result[key]);
} }
}); });