All checks were successful
CI Monitor MIflow / build-image (push) Successful in 45s
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
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<DB.Monitor | null>} - 返回监控项或null
|
|
*/
|
|
const getOne = (
|
|
project_id: string,
|
|
pipeline_id: string,
|
|
stage: string,
|
|
api_key: string
|
|
) =>
|
|
managePb404<DB.Monitor>(() =>
|
|
pbClient
|
|
.collection("monitor")
|
|
.getFirstListItem(
|
|
`project_id="${project_id}" && pipeline_id="${pipeline_id}" && stage="${stage}" && api_key="${api_key}"`
|
|
)
|
|
)
|
|
|
|
/**
|
|
* 获取所有监控项的完整列表
|
|
* @returns {Promise<DB.Monitor[]>} - 返回监控项的完整列表
|
|
*/
|
|
const getFullList = async (): Promise<DB.Monitor[]> =>
|
|
await pbClient.collection("monitor").getFullList<DB.Monitor>()
|
|
|
|
/**
|
|
* 创建一个监控项
|
|
* @param {Partial<DB.Monitor>} data - 监控项数据
|
|
* @returns {Promise<DB.Monitor>} - 返回创建的监控项
|
|
*/
|
|
const create = async (data: Partial<DB.Monitor>): Promise<DB.Monitor> =>
|
|
await pbClient.collection("monitor").create<DB.Monitor>(data)
|
|
|
|
/**
|
|
* 删除一个监控项
|
|
* @param {string} id - 监控项ID
|
|
* @returns {Promise<boolean>}
|
|
*/
|
|
const del = async (id: string): Promise<boolean> =>
|
|
await pbClient.collection("monitor").delete(id)
|
|
|
|
const monitor = {
|
|
create,
|
|
getOne,
|
|
del,
|
|
getFullList,
|
|
}
|
|
|
|
export default monitor
|