adds trail share
This commit is contained in:
57
web/src/lib/stores/list_share_store.ts
Normal file
57
web/src/lib/stores/list_share_store.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { ListShare } from "$lib/models/list_share";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
|
||||
export const shares: Writable<ListShare[]> = writable([])
|
||||
|
||||
|
||||
export async function list_share_index(list: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f('/api/v1/list-share?' + new URLSearchParams({
|
||||
filter: `list='${list}'`,
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
|
||||
const response: ListShare[] = await r.json();
|
||||
|
||||
shares.set(response);
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
export async function list_share_create(share: ListShare) {
|
||||
let r = await fetch('/api/v1/list-share', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(share),
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
}
|
||||
|
||||
export async function list_share_update(share: ListShare) {
|
||||
let r = await fetch('/api/v1/list-share/' + share.id, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(share),
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
}
|
||||
|
||||
export async function list_share_delete(share: ListShare) {
|
||||
const r = await fetch('/api/v1/list-share/' + share.id, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import { writable, type Writable } from "svelte/store";
|
||||
export const shares: Writable<TrailShare[]> = writable([])
|
||||
|
||||
|
||||
export async function trail_share_index(trail: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
export async function trail_share_index(data: {trail?: string, user?: string}, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
const r = await f('/api/v1/trail-share?' + new URLSearchParams({
|
||||
filter: `trail='${trail}'`,
|
||||
filter: data.trail ? `trail='${data.trail}'` : data.user ? `user='${data.user}'` : '',
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
@@ -20,7 +20,7 @@ export async function trail_share_index(trail: string, f: (url: RequestInfo | UR
|
||||
|
||||
shares.set(response);
|
||||
|
||||
return shares;
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function trail_share_create(share: TrailShare) {
|
||||
|
||||
if (!r.ok) {
|
||||
throw new ClientResponseError(await r.json())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function trail_share_update(share: TrailShare) {
|
||||
|
||||
Reference in New Issue
Block a user