Files
certd/packages/ui/certd-server/src/controller/user/mine/user-settings-controller.ts
T

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-04-17 00:06:49 +08:00
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { Constants, CrudController } from "@certd/lib-server";
import { UserSettingsService } from "../../../modules/mine/service/user-settings-service.js";
import { UserSettingsEntity } from "../../../modules/mine/entity/user-settings.js";
2023-06-07 23:36:42 +08:00
/**
*/
@Provide()
@Controller('/api/user/settings')
export class UserSettingsController extends CrudController<UserSettingsService> {
2023-06-07 23:36:42 +08:00
@Inject()
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 ?? {};
2024-10-10 02:15:05 +08:00
body.query.userId = this.getUserId();
2023-06-07 23:36:42 +08:00
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.query = body.query ?? {};
body.query.userId = this.getUserId();
2023-06-07 23:36:42 +08:00
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) {
2024-10-10 02:15:05 +08:00
bean.userId = this.getUserId();
2023-06-07 23:36:42 +08:00
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) {
2024-10-10 02:15:05 +08:00
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
2023-06-07 23:36:42 +08:00
return super.update(bean);
}
2023-06-27 09:29:43 +08:00
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
2024-10-10 02:15:05 +08:00
await this.service.checkUserId(id, this.getUserId());
2023-06-07 23:36:42 +08:00
return super.info(id);
}
2023-06-27 09:29:43 +08:00
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
2024-10-10 02:15:05 +08:00
await this.service.checkUserId(id, this.getUserId());
2023-06-07 23:36:42 +08:00
return super.delete(id);
}
2023-06-27 09:29:43 +08:00
@Post('/save', { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: UserSettingsEntity) {
2024-10-10 02:15:05 +08:00
bean.userId = this.getUserId();
2023-06-25 15:30:18 +08:00
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) {
2024-10-10 02:15:05 +08:00
const entity = await this.service.getByKey(key, this.getUserId());
2023-06-25 15:30:18 +08:00
return this.ok(entity);
}
2025-04-17 00:06:49 +08:00
2023-06-07 23:36:42 +08:00
}