2024-07-18 11:17:13 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
2024-10-03 22:03:49 +08:00
|
|
|
import { CrudController } from '@certd/lib-server';
|
|
|
|
|
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';
|
2024-08-05 12:49:44 +08:00
|
|
|
import { PipelineService } from '../../pipeline/service/pipeline-service.js';
|
2023-06-07 23:36:42 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/sys/settings')
|
2024-06-16 00:20:02 +08:00
|
|
|
export class SysSettingsController extends CrudController<SysSettingsService> {
|
2023-06-07 23:36:42 +08:00
|
|
|
@Inject()
|
2024-06-16 00:20:02 +08:00
|
|
|
service: SysSettingsService;
|
2024-08-05 12:49:44 +08:00
|
|
|
@Inject()
|
|
|
|
|
pipelineService: PipelineService;
|
2023-06-07 23:36:42 +08:00
|
|
|
|
|
|
|
|
getService() {
|
|
|
|
|
return this.service;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/page', { summary: 'sys:settings:view' })
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/list', { summary: 'sys:settings:view' })
|
2023-06-07 23:36:42 +08:00
|
|
|
async list(@Body(ALL) body) {
|
|
|
|
|
body.userId = this.ctx.user.id;
|
|
|
|
|
return super.list(body);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/add', { summary: 'sys:settings:edit' })
|
2023-06-07 23:36:42 +08:00
|
|
|
async add(@Body(ALL) bean) {
|
|
|
|
|
bean.userId = this.ctx.user.id;
|
|
|
|
|
return super.add(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/update', { summary: 'sys:settings:edit' })
|
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);
|
|
|
|
|
}
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/info', { summary: 'sys:settings:view' })
|
2024-08-30 18:50:53 +08:00
|
|
|
async info(@Query('id') id: number) {
|
2023-06-07 23:36:42 +08:00
|
|
|
await this.service.checkUserId(id, this.ctx.user.id);
|
|
|
|
|
return super.info(id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/delete', { summary: 'sys:settings:edit' })
|
2024-08-30 18:50:53 +08:00
|
|
|
async delete(@Query('id') id: number) {
|
2023-06-07 23:36:42 +08:00
|
|
|
await this.service.checkUserId(id, this.ctx.user.id);
|
|
|
|
|
return super.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@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({});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 00:20:02 +08:00
|
|
|
@Post('/get', { summary: 'sys:settings:view' })
|
2023-06-25 15:30:18 +08:00
|
|
|
async get(@Query('key') key: string) {
|
2024-06-16 00:20:02 +08:00
|
|
|
const entity = await this.service.getByKey(key);
|
2023-06-25 15:30:18 +08:00
|
|
|
return this.ok(entity);
|
|
|
|
|
}
|
2024-06-16 00:20:02 +08:00
|
|
|
|
|
|
|
|
// 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);
|
2024-06-16 00:20:02 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2024-08-05 12:49:44 +08:00
|
|
|
@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
|
|
|
}
|