import { RecordModel } from "pocketbase" import { AppInfoModel } from "../../constant/config" import { managePbError } from "../../utils/pbTools" import pbClient from "../pbClient" export interface GroupSummarySubscription { app: string initiator: string terminator: string chatId: string timeScope: "daily" | "weekly" } export type GroupSummarySubscriptionModel = GroupSummarySubscription & RecordModel export interface GrpSumSubWithApp extends GroupSummarySubscriptionModel { expand: { app: AppInfoModel } } const create = async (subscription: GroupSummarySubscription) => managePbError(() => pbClient.collection("groupSummarySubscription").create(subscription) ) const update = async ( id: string, subscription: Partial ) => managePbError(() => pbClient.collection("groupSummarySubscription").update(id, subscription) ) const getAll = async (filter: string = "") => managePbError(() => pbClient.collection("groupSummarySubscription").getFullList({ filter, expand: "app", }) ) const getByFilter = async (filter: string) => managePbError(() => pbClient .collection("groupSummarySubscription") .getFirstListItem(filter, { expand: "app" }) ) const grpSumSub = { create, update, getAll, getByFilter, } export default grpSumSub