| 123456789101112131415161718192021222324252627282930313233343536373839 |
- async function sendOrder(order, token) {
- console.log("Enviando orden:", order);
- 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;
- }
- }
- async function getProducts(token){
- const response = await fetch("/api/products/", {
- 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();
- return data.products;
- }
- export {sendOrder, getProducts}
|