* 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
18 lines
439 B
TypeScript
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;
|
|
}
|