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( async () => await pbClient.collection("pipeline").getOne(id) ) /** * 检索项目的最新管道。 * @param project_id 项目的 ID。 * @returns 一个解析为最新管道对象的 promise。 */ const getLatestOne = (project_id: string) => { return managePb404( async () => await pbClient .collection("pipeline") .getFirstListItem(`project_id="${project_id}"`, { sort: "-created_at", }) ) } /** * 创建一个新的管道。 * @param data 新管道的数据。 * @returns 一个解析为创建的管道对象的 promise。 */ const create = async (data: Partial) => await pbClient.collection("pipeline").create(data) const pipeline = { create, getOne, getLatestOne, } export default pipeline