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