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 { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
|
|
|
|
import { GroupService } from "../../../modules/basic/service/group-service.js";
|
|
|
|
|
import { ApiTags } from "@midwayjs/swagger";
|
2026-07-12 02:29:54 +08:00
|
|
|
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
2025-10-21 22:28:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通知
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
2026-05-31 01:41:33 +08:00
|
|
|
@Controller("/api/basic/group")
|
|
|
|
|
@ApiTags(["basic-group"])
|
2025-10-21 22:28:02 +08:00
|
|
|
export class GroupController extends CrudController<GroupService> {
|
|
|
|
|
@Inject()
|
|
|
|
|
service: GroupService;
|
|
|
|
|
@Inject()
|
|
|
|
|
authService: AuthService;
|
|
|
|
|
|
|
|
|
|
getService(): GroupService {
|
|
|
|
|
return this.service;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-12 02:29:54 +08:00
|
|
|
getAuditType(): string {
|
2026-07-13 00:53:19 +08:00
|
|
|
return AuditType.pipelineGroup.value;
|
2026-07-12 02:29:54 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/page", { description: Constants.per.authOnly, summary: "查询分组分页列表" })
|
2025-10-21 22:28:02 +08:00
|
|
|
async page(@Body(ALL) body: any) {
|
2026-05-31 01:41:33 +08:00
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
2025-10-21 22:28:02 +08:00
|
|
|
body.query = body.query ?? {};
|
2026-02-13 21:28:17 +08:00
|
|
|
body.query.projectId = projectId;
|
2025-10-21 22:28:02 +08:00
|
|
|
delete body.query.userId;
|
|
|
|
|
const buildQuery = qb => {
|
2026-05-31 01:41:33 +08:00
|
|
|
qb.andWhere("user_id = :userId", { userId });
|
2025-10-21 22:28:02 +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-10-21 22:28:02 +08:00
|
|
|
async list(@Body(ALL) body: any) {
|
2026-05-31 01:41:33 +08:00
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
2025-10-21 22:28:02 +08:00
|
|
|
body.query = body.query ?? {};
|
2026-02-13 21:28:17 +08:00
|
|
|
body.query.projectId = projectId;
|
|
|
|
|
body.query.userId = userId;
|
2025-10-21 22:28:02 +08:00
|
|
|
return await super.list(body);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/add", { description: Constants.per.authOnly, summary: "添加分组" })
|
2025-10-21 22:28:02 +08:00
|
|
|
async add(@Body(ALL) bean: any) {
|
2026-05-31 01:41:33 +08:00
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
2026-02-13 21:28:17 +08:00
|
|
|
bean.projectId = projectId;
|
|
|
|
|
bean.userId = userId;
|
2026-07-12 02:29:54 +08:00
|
|
|
const res = await super.add(bean);
|
|
|
|
|
this.auditLog({ content: `新增了分组「${bean.name}」(ID:${res.data})` });
|
|
|
|
|
return res;
|
2025-10-21 22:28:02 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/update", { description: Constants.per.authOnly, summary: "更新分组" })
|
2025-10-21 22:28:02 +08:00
|
|
|
async update(@Body(ALL) bean) {
|
2026-02-13 21:28:17 +08:00
|
|
|
await this.checkOwner(this.getService(), bean.id, "write");
|
2025-10-21 22:28:02 +08:00
|
|
|
delete bean.userId;
|
2026-02-13 21:28:17 +08:00
|
|
|
delete bean.projectId;
|
2026-07-12 02:29:54 +08:00
|
|
|
const res = await super.update(bean);
|
|
|
|
|
this.auditLog({ content: `修改了分组「${bean.name}」(ID:${bean.id})` });
|
|
|
|
|
return res;
|
2025-10-21 22:28:02 +08:00
|
|
|
}
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/info", { description: Constants.per.authOnly, summary: "查询分组详情" })
|
|
|
|
|
async info(@Query("id") id: number) {
|
2026-02-13 21:28:17 +08:00
|
|
|
await this.checkOwner(this.getService(), id, "read");
|
2025-10-21 22:28:02 +08:00
|
|
|
return await super.info(id);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/delete", { description: Constants.per.authOnly, summary: "删除分组" })
|
|
|
|
|
async delete(@Query("id") id: number) {
|
2026-02-13 21:28:17 +08:00
|
|
|
await this.checkOwner(this.getService(), id, "write");
|
2026-07-12 02:29:54 +08:00
|
|
|
const res = await super.delete(id);
|
|
|
|
|
this.auditLog({ content: `删除了分组(ID:${id})` });
|
|
|
|
|
return res;
|
2025-10-21 22:28:02 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 01:41:33 +08:00
|
|
|
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有分组" })
|
|
|
|
|
async all(@Query("type") type: string) {
|
|
|
|
|
const { projectId, userId } = await this.getProjectUserIdRead();
|
2025-10-21 22:28:02 +08:00
|
|
|
const list: any = await this.service.find({
|
|
|
|
|
where: {
|
2026-02-13 21:28:17 +08:00
|
|
|
projectId,
|
|
|
|
|
userId,
|
2025-10-21 22:28:02 +08:00
|
|
|
type,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return this.ok(list);
|
|
|
|
|
}
|
|
|
|
|
}
|