tachybase_todo/packages/plugins/workflow/src/server/utils.ts
Junyi 9f8460ca22
feat(plugin-workflow): change to unlimited depth preloading associations in workflow (#2142)
* refactor(plugin-snapshot): move AppendsTreeSelect component into client package

* refactor(plugin-workflow): change all appends fields select to AppendsTreeSelect

* refactor(plugin-workflow): change appends and toJSON logic on server side

* fix(plugin-workflow): fix toJSON logic and build error

* fix(plugin-workflow): fix missing component injection

* fix(plugin-workflow): fix cycle association in variables

* refactor(client): change AppendsTreeSelect to lazy load

* fix(client): fix lazy load in option
2023-07-17 20:36:17 -07:00

18 lines
439 B
TypeScript

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);
}
const result = data.get();
Object.keys((<typeof Model>data.constructor).associations).forEach((key) => {
if (result[key] != null) {
result[key] = toJSON(result[key]);
}
});
return result;
}