70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import PocketBase, { RecordModel } from "pocketbase"
|
||
import { Logger } from "winston"
|
||
|
||
import { AppInfoModel } from "../../constant/config"
|
||
import PbToolBase, { WithExpand } from "../base"
|
||
|
||
const DB_NAME = "receiveGroup"
|
||
|
||
/**
|
||
* 接收组接口,定义接收消息的群组数据结构
|
||
* 用于管理消息接收者分组信息
|
||
*/
|
||
export interface ReceiveGroup {
|
||
/** 接收组名称 */
|
||
name: string
|
||
/** 聊天群组ID列表,可选 */
|
||
chatId?: string[]
|
||
/** 用户ID列表,可选 */
|
||
userId?: string[]
|
||
}
|
||
|
||
/**
|
||
* 接收组模型类型,结合 ReceiveGroup 接口和 PocketBase 的 RecordModel
|
||
*/
|
||
export type ReceiveGroupModel = ReceiveGroup & RecordModel
|
||
|
||
/**
|
||
* 带应用信息的接收组模型类型
|
||
* 扩展了基础接收组模型,包含关联的应用信息
|
||
*/
|
||
export type ReceiveGroupModelWithApp = ReceiveGroupModel &
|
||
WithExpand<{ app: AppInfoModel }>
|
||
|
||
/**
|
||
* 接收组数据库操作类
|
||
*
|
||
* 提供接收组相关的数据库操作,继承自 PbToolBase 基础类
|
||
* 用于管理消息发送目标群组,支持查询带应用信息的接收组
|
||
*
|
||
* @extends PbToolBase<ReceiveGroupModel> 基础数据库操作类
|
||
*/
|
||
class ReceiveGroupDB extends PbToolBase<ReceiveGroupModel> {
|
||
/**
|
||
* 创建 ReceiveGroupDB 实例
|
||
*
|
||
* @param pbClient - PocketBase 客户端实例,用于与数据库通信
|
||
* @param logger - 日志记录器实例,用于记录操作日志
|
||
*/
|
||
constructor(pbClient: PocketBase, logger: Logger) {
|
||
super(DB_NAME, pbClient, logger)
|
||
}
|
||
|
||
/**
|
||
* 获取带应用信息的接收组
|
||
*
|
||
* @param id - 接收组ID
|
||
* @returns 带应用信息的接收组记录,失败时返回 null
|
||
*
|
||
* @example
|
||
* ```typescript
|
||
* const groupWithApp = await receiveGroupDB.getWithApp("group123");
|
||
* ```
|
||
*/
|
||
public getWithApp = (id: string) => {
|
||
return this.get<ReceiveGroupModelWithApp>(id, { expand: "app" })
|
||
}
|
||
}
|
||
|
||
export default ReceiveGroupDB
|