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

100 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-06-19 18:17:35 +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';
2025-06-29 17:41:54 +08:00
import { checkPlus } from '@certd/plus-core';
2025-06-19 18:17:35 +08:00
/**
* 流水线模版
*/
@Provide()
@Controller('/api/pi/template')
export class TemplateController extends CrudController<TemplateService> {
@Inject()
service: TemplateService;
getService() {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
2026-02-13 00:41:40 +08:00
2025-06-19 18:17:35 +08:00
body.query = body.query ?? {};
delete body.query.userId;
2026-02-13 00:41:40 +08:00
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
2025-06-19 18:17:35 +08:00
const buildQuery = qb => {
2026-02-13 00:41:40 +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);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body) {
body.query = body.query ?? {};
2026-02-13 00:41:40 +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);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean) {
2026-02-13 00:41:40 +08:00
const { projectId, userId } = await this.getProjectUserIdRead()
bean.userId = userId;
bean.projectId = projectId
2025-06-29 17:41:54 +08:00
checkPlus()
2025-06-19 18:17:35 +08:00
return super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
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;
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
2026-02-13 00:41:40 +08:00
await this.checkOwner(this.service, id, "read");
2025-06-19 18:17:35 +08:00
return super.info(id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
2026-02-13 00:41:40 +08:00
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
}
@Post('/batchDelete', { summary: Constants.per.authOnly })
async batchDelete(@Body('ids') ids: number[]) {
2026-02-13 00:41:40 +08:00
const { userId ,projectId } = await this.getProjectUserIdWrite()
await this.service.batchDelete(ids, userId,projectId);
2025-06-19 18:17:35 +08:00
return this.ok({});
}
@Post('/detail', { summary: Constants.per.authOnly })
async detail(@Query('id') id: number) {
2026-02-13 00:41:40 +08:00
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);
}
2025-06-25 18:18:57 +08:00
@Post('/createPipelineByTemplate', { summary: Constants.per.authOnly })
async createPipelineByTemplate(@Body(ALL) body: any) {
2026-02-13 00:41:40 +08:00
const { userId ,projectId } = await this.getProjectUserIdWrite()
body.userId = userId;
body.projectId = projectId
2025-06-29 17:41:54 +08:00
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
}