60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
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<GroupSummarySubscriptionModel>(() =>
|
|
pbClient.collection("groupSummarySubscription").create(subscription)
|
|
)
|
|
|
|
const update = async (
|
|
id: string,
|
|
subscription: Partial<GroupSummarySubscription>
|
|
) =>
|
|
managePbError<GroupSummarySubscriptionModel>(() =>
|
|
pbClient.collection("groupSummarySubscription").update(id, subscription)
|
|
)
|
|
|
|
const getAll = async (filter: string = "") =>
|
|
managePbError<GrpSumSubWithApp[]>(() =>
|
|
pbClient.collection("groupSummarySubscription").getFullList({
|
|
filter,
|
|
expand: "app",
|
|
})
|
|
)
|
|
|
|
const getByFilter = async (filter: string) =>
|
|
managePbError<GrpSumSubWithApp>(() =>
|
|
pbClient
|
|
.collection("groupSummarySubscription")
|
|
.getFirstListItem(filter, { expand: "app" })
|
|
)
|
|
|
|
const grpSumSub = {
|
|
create,
|
|
update,
|
|
getAll,
|
|
getByFilter,
|
|
}
|
|
|
|
export default grpSumSub
|