import { DB } from "../../types/db" import { managePb404 } from "../../utils/pbTools" import pbClient from "../pbClient" /** * 获取一个监控项 * @param {string} project_id - 项目ID * @param {string} pipeline_id - 流水线ID * @param {string} stage - 阶段 * @param {string} api_key - API密钥 * @returns {Promise} - 返回监控项或null */ const getOne = ( project_id: string, pipeline_id: string, stage: string, api_key: string ) => managePb404(() => pbClient .collection("monitor") .getFirstListItem( `project_id="${project_id}" && pipeline_id="${pipeline_id}" && stage="${stage}" && api_key="${api_key}"` ) ) /** * 获取所有监控项的完整列表 * @returns {Promise} - 返回监控项的完整列表 */ const getFullList = async (): Promise => await pbClient.collection("monitor").getFullList() /** * 创建一个监控项 * @param {Partial} data - 监控项数据 * @returns {Promise} - 返回创建的监控项 */ const create = async (data: Partial): Promise => await pbClient.collection("monitor").create(data) /** * 删除一个监控项 * @param {string} id - 监控项ID * @returns {Promise} */ const del = async (id: string): Promise => await pbClient.collection("monitor").delete(id) const monitor = { create, getOne, del, getFullList, } export default monitor