zhaoyingbo a4555ac862
All checks were successful
CI Monitor CI/CD / build-image (push) Successful in 29s
CI Monitor CI/CD / deploy (push) Successful in 30s
feat: 接入eslint
2024-07-24 10:56:26 +00:00

46 lines
1.1 KiB
TypeScript

import { DB } from "../../types/db";
import { managePb404 } from "../../utils/pbTools";
import pbClient from "../pbClient";
/**
* 通过其 ID 检索一个管道。
* @param id 管道的 ID。
* @returns 一个解析为管道对象的 promise。
*/
const getOne = (id: string) =>
managePb404<DB.Pipeline>(
async () => await pbClient.collection("pipeline").getOne(id)
);
/**
* 检索项目的最新管道。
* @param project_id 项目的 ID。
* @returns 一个解析为最新管道对象的 promise。
*/
const getLatestOne = (project_id: string) => {
return managePb404<DB.Pipeline>(
async () =>
await pbClient
.collection("pipeline")
.getFirstListItem(`project_id="${project_id}"`, {
sort: "-created_at",
})
);
};
/**
* 创建一个新的管道。
* @param data 新管道的数据。
* @returns 一个解析为创建的管道对象的 promise。
*/
const create = async (data: Partial<DB.Pipeline>) =>
await pbClient.collection("pipeline").create<DB.Pipeline>(data);
const pipeline = {
create,
getOne,
getLatestOne,
};
export default pipeline;