2021-03-16 14:31:54 +08:00
|
|
|
import { Model, ModelCtor } from '@nocobase/database';
|
|
|
|
import { actions } from '@nocobase/actions';
|
2021-03-28 13:34:51 +08:00
|
|
|
import { flatToTree } from '../utils';
|
2021-03-16 14:31:54 +08:00
|
|
|
|
2021-04-18 15:17:19 +08:00
|
|
|
export const list = async (ctx, next) => {
|
2021-03-16 14:31:54 +08:00
|
|
|
await actions.common.list(ctx, async () => {
|
|
|
|
const items = ctx.body.rows as any;
|
|
|
|
ctx.body.rows = flatToTree(items.map(item => item.toJSON()), {
|
|
|
|
id: 'id',
|
|
|
|
parentId: 'parent_id',
|
|
|
|
children: 'children',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
await next();
|
|
|
|
}
|