Setup elysia treaty on client
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Printful } from "@blade-and-brawn/commerce";
|
||||
import { PUBLIC_API_URL } from "$env/static/public";
|
||||
import { onMount } from "svelte";
|
||||
import { api } from "$lib/api.js";
|
||||
|
||||
const { data } = $props();
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
isRunning: false,
|
||||
printfulProductIds: [] as number[],
|
||||
poll: async function () {
|
||||
const res = (await (
|
||||
await fetch(`${PUBLIC_API_URL}/products/sync`)
|
||||
).json()) as any;
|
||||
const res = await api.products.sync.get();
|
||||
if (res.data) {
|
||||
synchronizer.isRunning = res.data.isRunning;
|
||||
synchronizer.printfulProductIds =
|
||||
@@ -26,16 +24,11 @@
|
||||
},
|
||||
syncAll: async () => {
|
||||
synchronizer.startPolling();
|
||||
await fetch(`${PUBLIC_API_URL}/products/sync`, { method: "POST" });
|
||||
await api.products.sync.post();
|
||||
},
|
||||
sync: async (printfulProductId: number) => {
|
||||
synchronizer.startPolling();
|
||||
await fetch(
|
||||
`${PUBLIC_API_URL}/products/sync/${printfulProductId}`,
|
||||
{
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
await api.products.sync.post({ printfulProductId });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -85,12 +78,13 @@
|
||||
<td
|
||||
><button
|
||||
onclick={async () => {
|
||||
const productData = (await (
|
||||
await fetch(
|
||||
`${PUBLIC_API_URL}/products/${printfulProduct.id}`,
|
||||
)
|
||||
).json()) as any;
|
||||
console.log(productData);
|
||||
const res = await api
|
||||
.products({
|
||||
printfulProductId:
|
||||
printfulProduct.id,
|
||||
})
|
||||
.get();
|
||||
console.log(res.data);
|
||||
}}
|
||||
class="cursor-pointer underline"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user