Files
certd/packages/ui/certd-server/src/modules/sys/settings/controller/sys-settings-controller.ts

104 lines
3.2 KiB
TypeScript
Raw Normal View History

2024-07-18 11:17:13 +08:00
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController, SysEmailConf } from '@certd/lib-server';
2024-10-03 22:03:49 +08:00
import { SysSettingsService } from '@certd/lib-server';
2024-07-15 00:30:33 +08:00
import { SysSettingsEntity } from '../entity/sys-settings.js';
2024-10-03 22:03:49 +08:00
import { SysPublicSettings } from '@certd/lib-server';
2024-07-18 11:17:13 +08:00
import * as _ from 'lodash-es';
import { PipelineService } from '../../../pipeline/service/pipeline-service.js';
import { UserSettingsService } from '../../../mine/service/user-settings-service.js';
2023-06-07 23:36:42 +08:00
/**
*/
@Provide()
@Controller('/api/sys/settings')
export class SysSettingsController extends CrudController<SysSettingsService> {
2023-06-07 23:36:42 +08:00
@Inject()
service: SysSettingsService;
@Inject()
userSettingsService: UserSettingsService;
@Inject()
pipelineService: PipelineService;
2023-06-07 23:36:42 +08:00
getService() {
return this.service;
}
@Post('/page', { summary: 'sys:settings:view' })
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);
}
@Post('/list', { summary: 'sys:settings:view' })
2023-06-07 23:36:42 +08:00
async list(@Body(ALL) body) {
2024-10-10 02:15:05 +08:00
body.userId = this.getUserId();
2023-06-07 23:36:42 +08:00
return super.list(body);
}
@Post('/add', { summary: 'sys:settings:edit' })
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);
}
@Post('/update', { summary: 'sys:settings:edit' })
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());
2023-06-07 23:36:42 +08:00
return super.update(bean);
}
@Post('/info', { summary: 'sys:settings:view' })
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);
}
@Post('/delete', { summary: 'sys:settings:edit' })
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);
}
@Post('/save', { summary: 'sys:settings:edit' })
async save(@Body(ALL) bean: SysSettingsEntity) {
2023-06-25 15:30:18 +08:00
await this.service.save(bean);
return this.ok({});
}
@Post('/get', { summary: 'sys:settings:view' })
2023-06-25 15:30:18 +08:00
async get(@Query('key') key: string) {
const entity = await this.service.getByKey(key);
2023-06-25 15:30:18 +08:00
return this.ok(entity);
}
// savePublicSettings
@Post('/getEmailSettings', { summary: 'sys:settings:edit' })
async getEmailSettings(@Body(ALL) body) {
let conf = await this.service.getSetting<SysEmailConf>(SysEmailConf);
if (!conf.host && conf.usePlus != null) {
//到userSetting里面去找
const adminEmailSetting = await this.userSettingsService.getByKey('email', 1);
if (adminEmailSetting) {
const setting = JSON.parse(adminEmailSetting.setting);
conf = _.merge(conf, setting);
await this.service.saveSetting(conf);
}
}
return this.ok(conf);
}
// savePublicSettings
@Post('/savePublicSettings', { summary: 'sys:settings:edit' })
async savePublicSettings(@Body(ALL) body) {
2024-07-18 11:17:13 +08:00
const setting = new SysPublicSettings();
_.merge(setting, body);
await this.service.savePublicSettings(setting);
return this.ok({});
}
@Post('/stopOtherUserTimer', { summary: 'sys:settings:edit' })
async stopOtherUserTimer(@Body(ALL) body) {
await this.pipelineService.stopOtherUserPipeline(1);
return this.ok({});
}
2023-06-07 23:36:42 +08:00
}