Files
certd/packages/ui/certd-server/src/modules/pipeline/controller/pipeline-controller.ts
T

91 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-01-29 13:44:19 +08:00
import {
ALL,
Body,
Controller,
Inject,
Post,
Provide,
Query,
} from '@midwayjs/decorator';
import { CrudController } from '../../../basic/crud-controller';
import { PipelineService } from '../service/pipeline-service';
import { PipelineEntity } from '../entity/pipeline';
2023-06-27 09:29:43 +08:00
import { Constants } from '../../../basic/constants';
2023-07-03 11:45:32 +08:00
import { HistoryService } from '../service/history-service';
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;
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) {
body.query.userId = this.ctx.user.id;
const buildQuery = qb => {
qb.where({});
};
return super.page({ ...body, buildQuery });
}
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) {
bean.userId = this.ctx.user.id;
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) {
await this.service.checkUserId(bean.id, this.ctx.user.id);
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) {
bean.userId = this.ctx.user.id;
if (bean.id > 0) {
await this.service.checkUserId(bean.id, this.ctx.user.id);
}
await this.service.save(bean);
2023-05-24 15:41:35 +08:00
await this.service.registerTriggerById(bean.id);
2023-01-29 13:44:19 +08:00
return this.ok(bean.id);
}
2023-06-27 09:29:43 +08:00
@Post('/delete', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async delete(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.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 })
2023-01-29 13:44:19 +08:00
async detail(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
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 })
2023-01-29 13:44:19 +08:00
async trigger(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
await this.service.trigger(id);
return this.ok({});
}
2023-07-03 11:45:32 +08:00
@Post('/cancel', { summary: Constants.per.authOnly })
async cancel(@Query('historyId') historyId) {
await this.historyService.checkUserId(historyId, this.ctx.user.id);
await this.service.cancel(historyId);
return this.ok({});
}
2023-01-29 13:44:19 +08:00
}