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) => {
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)) {
return;
@ -42,11 +49,8 @@ export default class FormTrigger extends Trigger {
this.trigger(context);
};
async trigger(context) {
const { triggerWorkflows, values } = context.action.params;
if (!triggerWorkflows) {
return;
}
private async trigger(context) {
const { triggerWorkflows = '', values } = context.action.params;
const { currentUser } = context.state;

View File

@ -1,15 +1,15 @@
import { Model } from '@nocobase/database';
export function toJSON(data: Model | Model[]): object {
if (typeof data !== 'object' || !data) {
return data;
}
if (Array.isArray(data)) {
return data.map(toJSON);
}
if (!(data instanceof Model) || !data) {
return data;
}
const result = data.get();
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]);
}
});