| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- async function sendOrder(order, token) {
- try {
- const response = await fetch("/api/orders/send", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${token}`
- },
- body: JSON.stringify(order)
- });
- if (!response.ok) {
- const errorData = await response.json().catch(() => ({ message: "Respuesta no válida del servidor." }));
- throw new Error(errorData.message || `Error del servidor: ${response.status}`);
- }
- const data = await response.json();
- return data;
- } catch (error) {
- console.error("Error al enviar la orden:", error);
- throw error;
- }
- }
- export async function freeBeer(token, tableNumber) {
- try {
- const response = await fetch("/api/users/reward", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${token}`
- },
- body: JSON.stringify({ tableNumber })
- });
- if (!response.ok) {
- const errorData = await response.json().catch(() => ({ message: "Respuesta no válida del servidor." }));
- throw new Error(errorData.message || `Error del servidor: ${response.status}`);
- }
- const data = await response.json();
- return data;
- } catch (error) {
- console.error("Error al obtener cerveza gratis:", error);
- throw error;
- }
- }
- async function getProducts(token){
- const response = await fetch("/api/products?status=1", {
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${token}`
- }
- });
- if (!response.ok) {
- const errorData = await response.json().catch(() => ({ message: "Respuesta no válida del servidor." }));
- throw new Error(errorData.message || `Error del servidor: ${response.status}`);
- }
- const data = await response.json();
- data.products.map(product => {
- if (product.promotion) {
- product.price = product.promotion.price;
- }
- })
- return data.products;
- }
- export {sendOrder, getProducts}
|