import { BASE_URL } from "$lib/apiutils";
import { PlacedBetsSchema } from "$lib/types";
import { createQuery } from "@tanstack/svelte-query";
import { z } from "zod";
const GetAllBetsBySheetIdRequestSchema = z.object({
id: z.string(),
authToken: z.string()
});
type GetAllBetsBySheetIdRequest = z.infer<typeof GetAllBetsBySheetIdRequestSchema>;
export async function getAllBetsBySheetId(req: GetAllBetsBySheetIdRequest) {
const response = await fetch(`${BASE_URL}/placed-bets/${req.id}`, {
credentials: "include",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + req.authToken
}
});
if (!response.ok) {
throw Error("error");
}
const r = await response.json();
const bets = PlacedBetsSchema.parse(r.bets);
return bets;
}
export function useGetAllBetsBySheetId(req: GetAllBetsBySheetIdRequest) {
return createQuery(() => ({
queryKey: ["bets", req.id, "all"],
queryFn: () => getAllBetsBySheetId(req),
}));
}
import { BASE_URL } from "$lib/apiutils";
import { PlacedBetsSchema } from "$lib/types";
import { createQuery } from "@tanstack/svelte-query";
import { z } from "zod";
const GetAllBetsBySheetIdRequestSchema = z.object({
id: z.string(),
authToken: z.string()
});
type GetAllBetsBySheetIdRequest = z.infer<typeof GetAllBetsBySheetIdRequestSchema>;
export async function getAllBetsBySheetId(req: GetAllBetsBySheetIdRequest) {
const response = await fetch(`${BASE_URL}/placed-bets/${req.id}`, {
credentials: "include",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + req.authToken
}
});
if (!response.ok) {
throw Error("error");
}
const r = await response.json();
const bets = PlacedBetsSchema.parse(r.bets);
return bets;
}
export function useGetAllBetsBySheetId(req: GetAllBetsBySheetIdRequest) {
return createQuery(() => ({
queryKey: ["bets", req.id, "all"],
queryFn: () => getAllBetsBySheetId(req),
}));
}