tachybase_todo/packages/plugins/@tachybase/plugin-workflow/src/server/utils.ts
sealday 3e58c54aa8 feat: 仓库二期 (#719)
Co-authored-by: hello@lv <2256334253@qq.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachybase#719
2024-05-08 16:20:31 +08:00

18 lines
460 B
TypeScript

import { Model } from '@tachybase/database';
export function toJSON(data: any): any {
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 && typeof result[key] === 'object') {
result[key] = toJSON(result[key]);
}
});
return result;
}