2020-10-24 15:34:43 +08:00
|
|
|
import { Context, Next } from './actions';
|
|
|
|
import { Action } from '@nocobase/resourcer';
|
|
|
|
|
|
|
|
export async function middleware(ctx: Context, next: Next) {
|
|
|
|
await next();
|
|
|
|
if (ctx.action instanceof Action) {
|
2021-02-22 11:11:49 +08:00
|
|
|
const { rows, ...meta } = ctx.body as any;
|
2020-10-24 15:34:43 +08:00
|
|
|
if (rows) {
|
|
|
|
ctx.body = {
|
|
|
|
data: rows,
|
|
|
|
meta,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
ctx.body = {
|
|
|
|
data: ctx.body,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default middleware;
|