2024-07-15 00:30:33 +08:00
|
|
|
import { ALL, Body, Post, Query } from '@midwayjs/core';
|
|
|
|
|
import { BaseController } from './base-controller.js';
|
2023-01-29 13:44:19 +08:00
|
|
|
|
2023-05-23 18:01:20 +08:00
|
|
|
export abstract class CrudController<T> extends BaseController {
|
2024-10-13 01:27:08 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2023-05-23 18:01:20 +08:00
|
|
|
abstract getService<T>();
|
2023-01-29 13:44:19 +08:00
|
|
|
|
|
|
|
|
@Post('/page')
|
2024-10-13 01:27:08 +08:00
|
|
|
async page(@Body(ALL) body: any) {
|
2024-10-14 00:19:55 +08:00
|
|
|
const pageRet = await this.getService().page({
|
|
|
|
|
query: body.query ?? {},
|
|
|
|
|
page: body.page,
|
|
|
|
|
sort: body.sort,
|
|
|
|
|
bq: body.bq,
|
|
|
|
|
});
|
2023-01-29 13:44:19 +08:00
|
|
|
return this.ok(pageRet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/list')
|
2024-10-13 01:27:08 +08:00
|
|
|
async list(@Body(ALL) body: any) {
|
2024-10-14 00:19:55 +08:00
|
|
|
const listRet = await this.getService().list({
|
|
|
|
|
query: body.query ?? {},
|
|
|
|
|
order: body.order,
|
|
|
|
|
});
|
2023-01-29 13:44:19 +08:00
|
|
|
return this.ok(listRet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/add')
|
2024-10-13 01:27:08 +08:00
|
|
|
async add(@Body(ALL) bean: any) {
|
2024-05-30 10:12:48 +08:00
|
|
|
delete bean.id;
|
2023-01-29 13:44:19 +08:00
|
|
|
const id = await this.getService().add(bean);
|
|
|
|
|
return this.ok(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/info')
|
2024-10-13 01:27:08 +08:00
|
|
|
async info(@Query('id') id: number) {
|
2023-01-29 13:44:19 +08:00
|
|
|
const bean = await this.getService().info(id);
|
|
|
|
|
return this.ok(bean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/update')
|
2024-10-13 01:27:08 +08:00
|
|
|
async update(@Body(ALL) bean: any) {
|
2023-01-29 13:44:19 +08:00
|
|
|
await this.getService().update(bean);
|
|
|
|
|
return this.ok(null);
|
|
|
|
|
}
|
2024-08-04 02:35:45 +08:00
|
|
|
|
2023-01-29 13:44:19 +08:00
|
|
|
@Post('/delete')
|
2024-10-13 01:27:08 +08:00
|
|
|
async delete(@Query('id') id: number) {
|
2023-01-29 13:44:19 +08:00
|
|
|
await this.getService().delete([id]);
|
|
|
|
|
return this.ok(null);
|
|
|
|
|
}
|
2024-12-19 01:21:55 +08:00
|
|
|
|
|
|
|
|
@Post('/deleteByIds')
|
|
|
|
|
async deleteByIds(@Body('ids') ids: number[]) {
|
|
|
|
|
await this.getService().delete(ids);
|
|
|
|
|
return this.ok(null);
|
|
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|