30 lines
783 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { DB } from "../../types/db"
import { managePb404 } from "../../utils/pbTools"
import pbClient from "../pbClient"
/**
* 从数据库检索一个通知。
* @param id 要检索的通知的ID。
* @returns 如果找到返回解析为通知对象的promise如果未找到抛出404错误。
*/
const getOne = (id: string) =>
managePb404<DB.Notify>(
async () =>
await pbClient.collection("notify").getFirstListItem(`build_id="${id}"`)
)
/**
* 创建一个新的通知。
* @param data 新通知的数据。
* @returns 返回解析为已创建通知对象的promise。
*/
const create = async (data: Partial<DB.Notify>) =>
await pbClient.collection("notify").create<DB.Notify>(data)
const notify = {
create,
getOne,
}
export default notify