2024-07-15 00:30:33 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
2024-10-09 02:34:28 +08:00
|
|
|
import { Constants, CrudController, SysSettingsService } from '@certd/lib-server';
|
2024-07-15 00:30:33 +08:00
|
|
|
import { PipelineService } from '../service/pipeline-service.js';
|
|
|
|
|
import { PipelineEntity } from '../entity/pipeline.js';
|
|
|
|
|
import { HistoryService } from '../service/history-service.js';
|
2024-10-07 03:21:16 +08:00
|
|
|
import { AuthService } from '../../sys/authority/service/auth-service.js';
|
2023-01-29 13:44:19 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 证书
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/pi/pipeline')
|
2023-05-23 18:01:20 +08:00
|
|
|
export class PipelineController extends CrudController<PipelineService> {
|
2023-01-29 13:44:19 +08:00
|
|
|
@Inject()
|
|
|
|
|
service: PipelineService;
|
2023-07-03 11:45:32 +08:00
|
|
|
@Inject()
|
|
|
|
|
historyService: HistoryService;
|
2024-08-05 12:49:44 +08:00
|
|
|
@Inject()
|
|
|
|
|
authService: AuthService;
|
|
|
|
|
@Inject()
|
|
|
|
|
sysSettingsService: SysSettingsService;
|
2023-01-29 13:44:19 +08:00
|
|
|
|
|
|
|
|
getService() {
|
|
|
|
|
return this.service;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/page', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async page(@Body(ALL) body) {
|
2024-08-05 12:49:44 +08:00
|
|
|
const isAdmin = await this.authService.isAdmin(this.ctx);
|
|
|
|
|
const publicSettings = await this.sysSettingsService.getPublicSettings();
|
|
|
|
|
if (!(publicSettings.managerOtherUserPipeline && isAdmin)) {
|
2024-10-10 02:15:05 +08:00
|
|
|
body.query.userId = this.getUserId();
|
2024-08-05 12:49:44 +08:00
|
|
|
}
|
2024-08-04 02:35:45 +08:00
|
|
|
|
|
|
|
|
const title = body.query.title;
|
|
|
|
|
delete body.query.title;
|
|
|
|
|
|
2023-01-29 13:44:19 +08:00
|
|
|
const buildQuery = qb => {
|
2024-08-04 02:35:45 +08:00
|
|
|
if (title) {
|
|
|
|
|
qb.where('title like :title', { title: `%${title}%` });
|
|
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
};
|
2024-08-04 02:35:45 +08:00
|
|
|
if (!body.sort || !body.sort?.prop) {
|
|
|
|
|
body.sort = { prop: 'order', asc: false };
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 10:12:02 +08:00
|
|
|
const pageRet = await this.getService().page(body?.query, body?.page, body?.sort, buildQuery);
|
|
|
|
|
return this.ok(pageRet);
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/add', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async add(@Body(ALL) bean: PipelineEntity) {
|
2024-10-10 02:15:05 +08:00
|
|
|
bean.userId = this.getUserId();
|
2023-01-29 13:44:19 +08:00
|
|
|
return super.add(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/update', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async update(@Body(ALL) bean) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
|
2023-01-29 13:44:19 +08:00
|
|
|
return super.update(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/save', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async save(@Body(ALL) bean: PipelineEntity) {
|
|
|
|
|
if (bean.id > 0) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
|
2024-10-10 14:57:26 +08:00
|
|
|
} else {
|
|
|
|
|
bean.userId = this.getUserId();
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
|
|
|
|
await this.service.save(bean);
|
|
|
|
|
return this.ok(bean.id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/delete', { summary: Constants.per.authOnly })
|
2024-08-30 18:50:53 +08:00
|
|
|
async delete(@Query('id') id: number) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
2023-06-28 12:46:29 +08:00
|
|
|
await this.service.delete(id);
|
|
|
|
|
return this.ok({});
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/detail', { summary: Constants.per.authOnly })
|
2024-08-30 18:50:53 +08:00
|
|
|
async detail(@Query('id') id: number) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
2023-01-29 13:44:19 +08:00
|
|
|
const detail = await this.service.detail(id);
|
|
|
|
|
return this.ok(detail);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/trigger', { summary: Constants.per.authOnly })
|
2024-09-02 18:36:12 +08:00
|
|
|
async trigger(@Query('id') id: number, @Query('stepId') stepId?: string) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
2024-09-02 18:36:12 +08:00
|
|
|
await this.service.trigger(id, stepId);
|
2023-01-29 13:44:19 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2023-07-03 11:45:32 +08:00
|
|
|
|
|
|
|
|
@Post('/cancel', { summary: Constants.per.authOnly })
|
2024-08-30 18:50:53 +08:00
|
|
|
async cancel(@Query('historyId') historyId: number) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.historyService, historyId);
|
2023-07-03 11:45:32 +08:00
|
|
|
await this.service.cancel(historyId);
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|