This commit is contained in:
xiaojunnuo
2025-01-15 01:26:39 +08:00
parent d6b3142a02
commit 6877b865a7
4 changed files with 10 additions and 10 deletions
@@ -0,0 +1,70 @@
import { Rule, RuleType } from '@midwayjs/validate';
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server';
import { CodeService } from '../../../modules/basic/service/code-service.js';
import { EmailService } from '../../../modules/basic/service/email-service.js';
export class SmsCodeReq {
@Rule(RuleType.string().required())
phoneCode: string;
@Rule(RuleType.string().required())
mobile: string;
@Rule(RuleType.string().required().max(10))
randomStr: string;
@Rule(RuleType.string().required().max(4))
imgCode: string;
}
export class EmailCodeReq {
@Rule(RuleType.string().required())
email: string;
@Rule(RuleType.string().required().max(10))
randomStr: string;
@Rule(RuleType.string().required().max(4))
imgCode: string;
}
/**
*/
@Provide()
@Controller('/api/basic/code')
export class BasicController extends BaseController {
@Inject()
codeService: CodeService;
@Inject()
emailService: EmailService;
@Post('/sendSmsCode', { summary: Constants.per.guest })
public async sendSmsCode(
@Body(ALL)
body: SmsCodeReq
) {
await this.codeService.checkCaptcha(body.randomStr, body.imgCode);
await this.codeService.sendSmsCode(body.phoneCode, body.mobile, body.randomStr);
return this.ok(null);
}
@Post('/sendEmailCode', { summary: Constants.per.guest })
public async sendEmailCode(
@Body(ALL)
body: EmailCodeReq
) {
await this.codeService.checkCaptcha(body.randomStr, body.imgCode);
await this.codeService.sendEmailCode(body.email, body.randomStr);
// 设置缓存内容
return this.ok(null);
}
@Get('/captcha', { summary: Constants.per.guest })
public async getCaptcha(@Query('randomStr') randomStr: any) {
const captcha = await this.codeService.generateCaptcha(randomStr);
this.ctx.res.setHeader('Content-Type', 'image/svg+xml');
return captcha.data;
}
}
@@ -0,0 +1,125 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController, SysSettingsService } from '@certd/lib-server';
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
import { PipelineEntity } from '../../../modules/pipeline/entity/pipeline.js';
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
/**
* 证书
*/
@Provide()
@Controller('/api/pi/pipeline')
export class PipelineController extends CrudController<PipelineService> {
@Inject()
service: PipelineService;
@Inject()
historyService: HistoryService;
@Inject()
authService: AuthService;
@Inject()
sysSettingsService: SysSettingsService;
getService() {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
const isAdmin = await this.authService.isAdmin(this.ctx);
const publicSettings = await this.sysSettingsService.getPublicSettings();
if (!(publicSettings.managerOtherUserPipeline && isAdmin)) {
body.query.userId = this.getUserId();
}
const title = body.query.title;
delete body.query.title;
const buildQuery = qb => {
if (title) {
qb.andWhere('(title like :title or content like :content)', { title: `%${title}%`, content: `%${title}%` });
}
};
if (!body.sort || !body.sort?.prop) {
body.sort = { prop: 'order', asc: false };
}
const pageRet = await this.getService().page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery,
});
return this.ok(pageRet);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.getUserId();
return super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
delete bean.userId;
return super.update(bean);
}
@Post('/save', { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: PipelineEntity) {
if (bean.id > 0) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
} else {
bean.userId = this.getUserId();
}
await this.service.save(bean);
return this.ok(bean.id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
await this.service.delete(id);
return this.ok({});
}
@Post('/detail', { summary: Constants.per.authOnly })
async detail(@Query('id') id: number) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
const detail = await this.service.detail(id);
return this.ok(detail);
}
@Post('/trigger', { summary: Constants.per.authOnly })
async trigger(@Query('id') id: number, @Query('stepId') stepId?: string) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
await this.service.trigger(id, stepId);
return this.ok({});
}
@Post('/cancel', { summary: Constants.per.authOnly })
async cancel(@Query('historyId') historyId: number) {
await this.authService.checkEntityUserId(this.ctx, this.historyService, historyId);
await this.service.cancel(historyId);
return this.ok({});
}
@Post('/count', { summary: Constants.per.authOnly })
async count() {
const count = await this.service.count({ userId: this.getUserId() });
return this.ok({ count });
}
@Post('/batchDelete', { summary: Constants.per.authOnly })
async batchDelete(@Body('ids') ids: number[]) {
await this.service.batchDelete(ids, this.getUserId());
return this.ok({});
}
@Post('/batchUpdateGroup', { summary: Constants.per.authOnly })
async batchUpdateGroup(@Body('ids') ids: number[], @Body('groupId') groupId: number) {
await this.service.batchUpdateGroup(ids, groupId, this.getUserId());
return this.ok({});
}
}
@@ -0,0 +1,77 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { PipelineGroupService } from '../../../modules/pipeline/service/pipeline-group-service.js';
/**
* 通知
*/
@Provide()
@Controller('/api/pi/pipeline/group')
export class PipelineGroupController extends CrudController<PipelineGroupService> {
@Inject()
service: PipelineGroupService;
@Inject()
authService: AuthService;
getService(): PipelineGroupService {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body: any) {
body.query = body.query ?? {};
delete body.query.userId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: this.getUserId() });
};
const res = await this.service.page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery,
});
return this.ok(res);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body: any) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
return await super.list(body);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: any) {
bean.userId = this.getUserId();
return await super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return await super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
await this.service.checkUserId(id, this.getUserId());
return await super.info(id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
await this.service.checkUserId(id, this.getUserId());
return await super.delete(id);
}
@Post('/all', { summary: Constants.per.authOnly })
async all() {
const list: any = await this.service.find({
where: {
userId: this.getUserId(),
},
});
return this.ok(list);
}
}
@@ -0,0 +1,43 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server';
import { PluginService } from '../../../modules/plugin/service/plugin-service.js';
import { PluginConfigService } from '../../../modules/plugin/service/plugin-config-service.js';
/**
* 插件
*/
@Provide()
@Controller('/api/pi/plugin')
export class PluginController extends BaseController {
@Inject()
service: PluginService;
@Inject()
pluginConfigService: PluginConfigService;
@Post('/list', { summary: Constants.per.authOnly })
async list(@Query(ALL) query: any) {
query.userId = this.getUserId();
const list = await this.service.getEnabledBuiltInList();
return this.ok(list);
}
@Post('/groups', { summary: Constants.per.authOnly })
async groups(@Query(ALL) query: any) {
query.userId = this.getUserId();
const group = await this.service.getEnabledBuildInGroup();
return this.ok(group);
}
@Post('/getDefineByType', { summary: Constants.per.authOnly })
async getDefineByType(@Body('type') type: string) {
const define = await this.service.getDefineByType(type);
return this.ok(define);
}
@Post('/config', { summary: Constants.per.authOnly })
async config(@Body(ALL) body: { id?: number; name?: string; type: string }) {
const config = await this.pluginConfigService.getPluginConfig(body);
return this.ok(config);
}
}