[PIE-29] New recipe form submission #15
@ -8,29 +8,29 @@ import {
|
|||||||
} from './schema'
|
} from './schema'
|
||||||
|
|
||||||
class APIClient {
|
class APIClient {
|
||||||
client: Pocketbase
|
pb: Pocketbase
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.client = new Pocketbase("http://localhost:4321")
|
this.pb = new Pocketbase("http://localhost:4321")
|
||||||
this.client.autoCancellation(false)
|
this.pb.autoCancellation(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRecipesPage(page: number, perPage: number = 30, options: RecordListOptions) {
|
async getRecipesPage(page: number, perPage: number = 30, options: RecordListOptions) {
|
||||||
return await this.client.collection<Recipe>(Collection.RECIPES).getList(page, perPage, options)
|
return await this.pb.collection<Recipe>(Collection.RECIPES).getList(page, perPage, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllRecipes() {
|
async getAllRecipes() {
|
||||||
return await this.client.collection<Recipe>(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' })
|
return await this.pb.collection<Recipe>(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRecipe(id: string) {
|
async getRecipe(id: string) {
|
||||||
return await this.client.collection<Recipe>(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' })
|
return await this.pb.collection<Recipe>(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMAGE
|
// IMAGE
|
||||||
async getImageURL(imgID: string, relative: boolean = true) {
|
async getImageURL(imgID: string, relative: boolean = true) {
|
||||||
const record = await this.client.collection(Collection.IMAGES).getOne(imgID)
|
const record = await this.pb.collection(Collection.IMAGES).getOne(imgID)
|
||||||
const res = this.client.files.getURL(record, record.image)
|
const res = this.pb.files.getURL(record, record.image)
|
||||||
return relative ? res.substring(21) : res
|
return relative ? res.substring(21) : res
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,11 +45,11 @@ class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAllTags() {
|
async getAllTags() {
|
||||||
return await this.client.collection<Tag>(Collection.TAGS).getFullList()
|
return await this.pb.collection<Tag>(Collection.TAGS).getFullList()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTag(name: string) {
|
async getTag(name: string) {
|
||||||
return await this.client.collection<Tag>(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` })
|
return await this.pb.collection<Tag>(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRecipesOfTag(tagName: string) {
|
async getRecipesOfTag(tagName: string) {
|
||||||
@ -60,7 +60,7 @@ class APIClient {
|
|||||||
}
|
}
|
||||||
const tag = tagResult.items[0]
|
const tag = tagResult.items[0]
|
||||||
|
|
||||||
return await this.client.collection<Recipe>(Collection.RECIPES).getFullList({
|
return await this.pb.collection<Recipe>(Collection.RECIPES).getFullList({
|
||||||
filter: `tags ~ '${tag.id}'`,
|
filter: `tags ~ '${tag.id}'`,
|
||||||
expand: 'ingredients,tags,steps,images,steps.ingredients'
|
expand: 'ingredients,tags,steps,images,steps.ingredients'
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user