Despliegue en VPS

This commit is contained in:
2026-06-07 21:25:45 +02:00
parent c06300833b
commit e08d959cf9
11 changed files with 3609 additions and 90 deletions
+28 -62
View File
@@ -1,65 +1,31 @@
// Capa de acceso a datos. Toda la app habla con el backend a través de este
// módulo. Para cambiar a Supabase u otro BaaS, basta con reescribir las dos
// funciones exportadas manteniendo la misma firma.
//
// Modelo de negocio:
// { id, name, category, address, description, contact, lat, lng, status, createdAt }
//
// `status` es uno de: "pending" | "approved" | "rejected".
const sampleBusinesses = [
{
id: "1",
name: "Café del Mercado",
category: "Cafetería",
address: "Plaza Mayor 3, Madrid",
description: "Café de especialidad y bollería artesana.",
contact: "hola@cafedelmercado.example",
lat: 40.4155,
lng: -3.7074,
status: "approved",
createdAt: "2025-01-10T10:00:00Z",
},
{
id: "2",
name: "Librería El Faro",
category: "Librería",
address: "Calle Luna 12, Madrid",
description: "Librería independiente con sección infantil.",
contact: "",
lat: 40.4221,
lng: -3.7059,
status: "approved",
createdAt: "2025-01-12T10:00:00Z",
},
{
id: "3",
name: "Taller Bicicletas Rueda",
category: "Servicios",
address: "Calle Embajadores 45, Madrid",
description: "Reparación y venta de segunda mano.",
contact: "+34 600 000 000",
lat: 40.4078,
lng: -3.7053,
status: "approved",
createdAt: "2025-01-15T10:00:00Z",
},
];
// Estado en memoria. Se reinicia al recargar. Suficiente para el prototipo.
let businesses = [...sampleBusinesses];
export function getApproved() {
return businesses.filter((b) => b.status === "approved");
export async function getApproved() {
const res = await fetch(`${import.meta.env.BASE_URL}api/businesses`);
if (!res.ok) throw new Error("Error cargando negocios");
return res.json();
}
export function submit(data) {
const newBusiness = {
...data,
id: crypto.randomUUID(),
status: "pending",
createdAt: new Date().toISOString(),
};
businesses = [...businesses, newBusiness];
return newBusiness;
export async function submit(data) {
const res = await fetch(`${import.meta.env.BASE_URL}api/businesses`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error("Error enviando propuesta");
return res.json();
}
export async function getPending() {
const res = await fetch(`${import.meta.env.BASE_URL}api/admin/pending`);
if (!res.ok) throw new Error("Error cargando pendientes");
return res.json();
}
export async function setStatus(id, status) {
const res = await fetch(`${import.meta.env.BASE_URL}api/admin/businesses/${id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status }),
});
if (!res.ok) throw new Error("Error actualizando estado");
return res.json();
}