diff --git a/src/data/pocketbase.ts b/src/data/pocketbase.ts index 8684c0a..7e68b9d 100644 --- a/src/data/pocketbase.ts +++ b/src/data/pocketbase.ts @@ -8,29 +8,29 @@ import { } from './schema' class APIClient { - client: Pocketbase + pb: Pocketbase constructor() { - this.client = new Pocketbase("http://localhost:4321") - this.client.autoCancellation(false) + this.pb = new Pocketbase("http://localhost:4321") + this.pb.autoCancellation(false) } async getRecipesPage(page: number, perPage: number = 30, options: RecordListOptions) { - return await this.client.collection(Collection.RECIPES).getList(page, perPage, options) + return await this.pb.collection(Collection.RECIPES).getList(page, perPage, options) } async getAllRecipes() { - return await this.client.collection(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' }) + return await this.pb.collection(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' }) } async getRecipe(id: string) { - return await this.client.collection(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' }) + return await this.pb.collection(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' }) } // IMAGE async getImageURL(imgID: string, relative: boolean = true) { - const record = await this.client.collection(Collection.IMAGES).getOne(imgID) - const res = this.client.files.getURL(record, record.image) + const record = await this.pb.collection(Collection.IMAGES).getOne(imgID) + const res = this.pb.files.getURL(record, record.image) return relative ? res.substring(21) : res } @@ -45,11 +45,11 @@ class APIClient { } async getAllTags() { - return await this.client.collection(Collection.TAGS).getFullList() + return await this.pb.collection(Collection.TAGS).getFullList() } async getTag(name: string) { - return await this.client.collection(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` }) + return await this.pb.collection(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` }) } async getRecipesOfTag(tagName: string) { @@ -60,7 +60,7 @@ class APIClient { } const tag = tagResult.items[0] - return await this.client.collection(Collection.RECIPES).getFullList({ + return await this.pb.collection(Collection.RECIPES).getFullList({ filter: `tags ~ '${tag.id}'`, expand: 'ingredients,tags,steps,images,steps.ingredients' })