// type Pizza = { // name: string; // // TODO ingredience // sizes: [ // size: number, // price: number, // ]; // } import { getBaseUrl } from "./Utils"; async function request( url: string, config: RequestInit = {} ): Promise { return fetch(getBaseUrl() + url, config).then(response => { if (!response.ok) { throw new Error(response.statusText); } return response.json() as TResponse; }); } const api = { get: (url: string) => request(url), post: (url: string, body: TBody) => request(url, { method: 'POST', body, headers: { 'Content-Type': 'application/json' } }), } export const getData = async () => { return await api.get('/api/data'); } export const getFood = async () => { return await api.get('/api/food'); } export const getPizzy = async () => { return await api.get('/api/pizza'); } export const createPizzaDay = async () => { return await api.post('/api/createPizzaDay', {}); } export const deletePizzaDay = async () => { return await api.post('/api/deletePizzaDay', {}); } export const updateChoice = async (name: string, choice: number | null) => { return await api.post('/api/updateChoice', JSON.stringify({ name, choice })); }