2026-05-31 01:41:33 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
|
|
|
|
import { Constants, CrudController } from "@certd/lib-server";
|
|
|
|
|
import { TemplateService } from "../../../modules/pipeline/service/template-service.js";
|
|
|
|
|
import { checkPlus } from "@certd/plus-core";
|
|
|
|
|
import { ApiTags } from "@midwayjs/swagger";
|
2025-06-19 18:17:35 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 流水线模版
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
2026-05-31 01:41:33 +08:00
|
|
|
@Controller("/api/pi/template")
|
|
|
|
|
@ApiTags(["pipeline-template"])
|
2025-06-19 18:17:35 +08:00
|
|
|
export class TemplateController extends CrudController<TemplateService> {
|
|
|
|
|
@Inject()
|
|
|
|
|
service: TemplateService;
|
|
|
|
|
|
|
|
|
|
getService() {
|
|
|
|
|
return this.service;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线模版分页列表" })
|
2025-06-19 18:17:35 +08:00
|
|
|
async page(@Body(ALL) body) {
|
|
|
|
|
body.query = body.query ?? {};
|
|
|
|
|
delete body.query.userId;
|
2026-05-31 01:41:33 +08:00
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
|
|
|
|
body.query.projectId = projectId;
|
|
|
|
|
|
2025-06-19 18:17:35 +08:00
|
|
|
const buildQuery = qb => {
|
2026-05-31 01:41:33 +08:00
|
|
|
qb.andWhere("user_id = :userId", { userId: userId });
|
2025-06-19 18:17:35 +08:00
|
|
|
};
|
|
|
|
|
const res = await this.service.page({
|
|
|
|
|
query: body.query,
|
|
|
|
|
page: body.page,
|
|
|
|
|
sort: body.sort,
|
|
|
|
|
buildQuery,
|
|
|
|
|
});
|
|
|
|
|
return this.ok(res);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线模版列表" })
|
2025-06-19 18:17:35 +08:00
|
|
|
async list(@Body(ALL) body) {
|
|
|
|
|
body.query = body.query ?? {};
|
2026-05-31 01:41:33 +08:00
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
|
|
|
|
body.query.projectId = projectId;
|
|
|
|
|
body.query.userId = userId;
|
2025-06-19 18:17:35 +08:00
|
|
|
return super.list(body);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线模版" })
|
2025-06-19 18:17:35 +08:00
|
|
|
async add(@Body(ALL) bean) {
|
2026-05-31 01:41:33 +08:00
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
2026-02-13 00:41:40 +08:00
|
|
|
bean.userId = userId;
|
2026-05-31 01:41:33 +08:00
|
|
|
bean.projectId = projectId;
|
|
|
|
|
checkPlus();
|
2025-06-19 18:17:35 +08:00
|
|
|
return super.add(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线模版" })
|
2025-06-19 18:17:35 +08:00
|
|
|
async update(@Body(ALL) bean) {
|
2026-02-13 00:41:40 +08:00
|
|
|
await this.checkOwner(this.service, bean.id, "write");
|
2025-06-19 18:17:35 +08:00
|
|
|
delete bean.userId;
|
2026-02-13 21:28:17 +08:00
|
|
|
delete bean.projectId;
|
2025-06-19 18:17:35 +08:00
|
|
|
return super.update(bean);
|
|
|
|
|
}
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
|
|
|
|
|
async info(@Query("id") id: number) {
|
|
|
|
|
await this.checkOwner(this.service, id, "read");
|
2025-06-19 18:17:35 +08:00
|
|
|
return super.info(id);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线模版" })
|
|
|
|
|
async delete(@Query("id") id: number) {
|
|
|
|
|
const { userId, projectId } = await this.getProjectUserIdWrite();
|
|
|
|
|
await this.service.batchDelete([id], userId, projectId);
|
2025-06-25 14:41:27 +08:00
|
|
|
return this.ok({});
|
2025-06-19 18:17:35 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除流水线模版" })
|
|
|
|
|
async batchDelete(@Body("ids") ids: number[]) {
|
|
|
|
|
const { userId, projectId } = await this.getProjectUserIdWrite();
|
|
|
|
|
await this.service.batchDelete(ids, userId, projectId);
|
2025-06-19 18:17:35 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
|
|
|
|
|
async detail(@Query("id") id: number) {
|
|
|
|
|
const { userId, projectId } = await this.getProjectUserIdRead();
|
|
|
|
|
const detail = await this.service.detail(id, userId, projectId);
|
2025-06-19 18:17:35 +08:00
|
|
|
return this.ok(detail);
|
|
|
|
|
}
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/createPipelineByTemplate", { description: Constants.per.authOnly, summary: "根据模版创建流水线" })
|
2025-06-25 18:18:57 +08:00
|
|
|
async createPipelineByTemplate(@Body(ALL) body: any) {
|
2026-05-31 01:41:33 +08:00
|
|
|
const { userId, projectId } = await this.getProjectUserIdWrite();
|
2026-02-13 00:41:40 +08:00
|
|
|
body.userId = userId;
|
2026-05-31 01:41:33 +08:00
|
|
|
body.projectId = projectId;
|
|
|
|
|
checkPlus();
|
2025-06-25 18:18:57 +08:00
|
|
|
const res = await this.service.createPipelineByTemplate(body);
|
|
|
|
|
return this.ok(res);
|
|
|
|
|
}
|
2025-06-19 18:17:35 +08:00
|
|
|
}
|