45 lines
866 B
TypeScript
45 lines
866 B
TypeScript
import { RecordModel } from "pocketbase"
|
|
|
|
import { managePbError } from "../../utils/pbTools"
|
|
import pbClient from "../pbClient"
|
|
|
|
const DB_NAME = "sheet"
|
|
|
|
export interface Sheet {
|
|
/***
|
|
* 表格区间
|
|
*/
|
|
range: string
|
|
/***
|
|
* 表格Token
|
|
*/
|
|
sheetToken: string
|
|
/***
|
|
* 表格链接
|
|
*/
|
|
sheetUrl: string
|
|
}
|
|
|
|
export type SheetModel = Sheet & RecordModel
|
|
|
|
const getByUrl = (sheetUrl: string) =>
|
|
managePbError<SheetModel>(() =>
|
|
pbClient.collection(DB_NAME).getFirstListItem(`sheetUrl = "${sheetUrl}"`)
|
|
)
|
|
|
|
const update = (id: string, sheet: Partial<SheetModel>) =>
|
|
managePbError<SheetModel>(() =>
|
|
pbClient.collection(DB_NAME).update(id, sheet)
|
|
)
|
|
|
|
const create = (sheet: Sheet) =>
|
|
managePbError<SheetModel>(() => pbClient.collection(DB_NAME).create(sheet))
|
|
|
|
const sheet = {
|
|
getByUrl,
|
|
update,
|
|
create,
|
|
}
|
|
|
|
export default sheet
|