2024-06-16 00:20:02 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/decorator";
|
|
|
|
|
import { CrudController } from "../../../basic/crud-controller";
|
|
|
|
|
import { Constants } from "../../../basic/constants";
|
|
|
|
|
import { UserSettingsService } from "../service/user-settings-service";
|
|
|
|
|
import { UserSettingsEntity } from "../entity/user-settings";
|
2023-06-07 23:36:42 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
2024-06-16 00:20:02 +08:00
|
|
|
@Controller('/api/user/settings')
|
|
|
|
|
export class UserSettingsController extends CrudController<UserSettingsService> {
|
2023-06-07 23:36:42 +08:00
|
|
|
@Inject()
|
2024-06-16 00:20:02 +08:00
|
|
|
service: UserSettingsService;
|
2023-06-07 23:36:42 +08:00
|
|
|
|
|
|
|
|
getService() {
|
|
|
|
|
return this.service;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/page', { summary: Constants.per.authOnly })
|
2023-06-07 23:36:42 +08:00
|
|
|
async page(@Body(ALL) body) {
|
|
|
|
|
body.query = body.query ?? {};
|
|
|
|
|
body.query.userId = this.ctx.user.id;
|
|
|
|
|
return super.page(body);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/list', { summary: Constants.per.authOnly })
|
2023-06-07 23:36:42 +08:00
|
|
|
async list(@Body(ALL) body) {
|
|
|
|
|
body.userId = this.ctx.user.id;
|
|
|
|
|
return super.list(body);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/add', { summary: Constants.per.authOnly })
|
2023-06-07 23:36:42 +08:00
|
|
|
async add(@Body(ALL) bean) {
|
|
|
|
|
bean.userId = this.ctx.user.id;
|
|
|
|
|
return super.add(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/update', { summary: Constants.per.authOnly })
|
2023-06-07 23:36:42 +08:00
|
|
|
async update(@Body(ALL) bean) {
|
|
|
|
|
await this.service.checkUserId(bean.id, this.ctx.user.id);
|
|
|
|
|
return super.update(bean);
|
|
|
|
|
}
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/info', { summary: Constants.per.authOnly })
|
2023-06-07 23:36:42 +08:00
|
|
|
async info(@Query('id') id) {
|
|
|
|
|
await this.service.checkUserId(id, this.ctx.user.id);
|
|
|
|
|
return super.info(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/delete', { summary: Constants.per.authOnly })
|
2023-06-07 23:36:42 +08:00
|
|
|
async delete(@Query('id') id) {
|
|
|
|
|
await this.service.checkUserId(id, this.ctx.user.id);
|
|
|
|
|
return super.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/save', { summary: Constants.per.authOnly })
|
2024-06-16 00:20:02 +08:00
|
|
|
async save(@Body(ALL) bean: UserSettingsEntity) {
|
2023-06-25 15:30:18 +08:00
|
|
|
bean.userId = this.ctx.user.id;
|
|
|
|
|
await this.service.save(bean);
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/get', { summary: Constants.per.authOnly })
|
2023-06-25 15:30:18 +08:00
|
|
|
async get(@Query('key') key: string) {
|
|
|
|
|
const entity = await this.service.getByKey(key, this.ctx.user.id);
|
|
|
|
|
return this.ok(entity);
|
|
|
|
|
}
|
2023-06-07 23:36:42 +08:00
|
|
|
}
|