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";
|
2025-12-28 23:36:53 +08:00
|
|
|
import { UserGrantSetting } from "../../../modules/mine/service/models.js";
|
|
|
|
|
import { isPlus } from "@certd/plus-core";
|
|
|
|
|
import { merge } from "lodash-es";
|
2026-03-15 14:01:34 +08:00
|
|
|
import { ApiTags } from "@midwayjs/swagger";
|
2023-06-07 23:36:42 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
2024-06-16 00:20:02 +08:00
|
|
|
@Controller('/api/user/settings')
|
2026-03-15 14:01:34 +08:00
|
|
|
@ApiTags(['mine'])
|
2024-06-16 00:20:02 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/page', { description: Constants.per.authOnly, summary: "查询用户设置分页列表" })
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/list', { description: Constants.per.authOnly, summary: "查询用户设置列表" })
|
2023-06-07 23:36:42 +08:00
|
|
|
async list(@Body(ALL) body) {
|
2024-12-09 02:24:30 +08:00
|
|
|
body.query = body.query ?? {};
|
|
|
|
|
body.query.userId = this.getUserId();
|
2023-06-07 23:36:42 +08:00
|
|
|
return super.list(body);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/add', { description: Constants.per.authOnly, summary: "添加用户设置" })
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/update', { description: Constants.per.authOnly, summary: "更新用户设置" })
|
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());
|
2024-12-01 02:10:40 +08:00
|
|
|
delete bean.userId;
|
2023-06-07 23:36:42 +08:00
|
|
|
return super.update(bean);
|
|
|
|
|
}
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/info', { description: Constants.per.authOnly, summary: "查询用户设置详情" })
|
2024-08-30 18:50:53 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/delete', { description: Constants.per.authOnly, summary: "删除用户设置" })
|
2024-08-30 18:50:53 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/save', { description: Constants.per.authOnly, summary: "保存用户设置" })
|
2024-06-16 00:20:02 +08:00
|
|
|
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({});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post('/get', { description: Constants.per.authOnly, summary: "获取用户设置" })
|
2023-06-25 15:30:18 +08:00
|
|
|
async get(@Query('key') key: string) {
|
2026-02-13 21:28:17 +08:00
|
|
|
const {projectId,userId} = await this.getProjectUserIdRead();
|
|
|
|
|
const entity = await this.service.getByKey(key, userId, projectId);
|
2023-06-25 15:30:18 +08:00
|
|
|
return this.ok(entity);
|
|
|
|
|
}
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post("/grant/get", { description: Constants.per.authOnly, summary: "获取授权设置" })
|
2025-12-28 23:36:53 +08:00
|
|
|
async grantSettingsGet() {
|
|
|
|
|
const userId = this.getUserId();
|
2026-02-13 21:28:17 +08:00
|
|
|
const setting = await this.service.getSetting<UserGrantSetting>(userId, null, UserGrantSetting);
|
2025-12-28 23:36:53 +08:00
|
|
|
return this.ok(setting);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 18:26:49 +08:00
|
|
|
@Post("/grant/save", { description: Constants.per.authOnly, summary: "保存授权设置" })
|
2025-12-28 23:36:53 +08:00
|
|
|
async grantSettingsSave(@Body(ALL) bean: UserGrantSetting) {
|
|
|
|
|
if (!isPlus()) {
|
2026-03-28 11:17:50 +08:00
|
|
|
throw new Error('本功能需要开通Certd专业版')
|
2025-12-28 23:36:53 +08:00
|
|
|
}
|
|
|
|
|
const userId = this.getUserId();
|
|
|
|
|
const setting = new UserGrantSetting();
|
|
|
|
|
merge(setting, bean);
|
|
|
|
|
|
2026-02-13 21:28:17 +08:00
|
|
|
await this.service.saveSetting(userId,null, setting);
|
2025-12-28 23:36:53 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 23:36:42 +08:00
|
|
|
}
|