From bc07d3288e8d989e0b34f8ccebff6209bfd17c02 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 8 Feb 2026 12:31:49 +0000 Subject: [PATCH] Actualizar servicios.html --- servicios.html | 870 ++++++++++++++++++++----------------------------- 1 file changed, 357 insertions(+), 513 deletions(-) diff --git a/servicios.html b/servicios.html index f37a3f4..0b4f9bb 100644 --- a/servicios.html +++ b/servicios.html @@ -1,543 +1,387 @@ - - - - - - Servicios - IntegraRepara - - - - - +import express from "express"; +import cors from "cors"; +import bcrypt from "bcryptjs"; +import jwt from "jsonwebtoken"; +import pg from "pg"; -
- +const { Pool } = pg; +const app = express(); -
-
- -
- -
-
-
-

- Servicios Activos -

-

Gestiona las reparaciones y sus estados.

-
- -
+app.use(cors()); +app.use(express.json()); -
- - - - - - - - - - - - - -
FechaCliente / DirecciónDetalleEstado
Cargando servicios...
-
-
+const { + DATABASE_URL, + JWT_SECRET, + EVOLUTION_BASE_URL, + EVOLUTION_API_KEY, + EVOLUTION_INSTANCE, +} = process.env; - + await client.query(` + DO $$ BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='services' AND column_name='status_id') THEN + ALTER TABLE services ADD COLUMN status_id INT REFERENCES service_statuses(id) ON DELETE SET NULL; + END IF; + END $$; + `); - +app.post("/auth/verify", async (req, res) => { + try { const { phone, code } = req.body; const p = normalizePhone(phone); const q = await pool.query(`SELECT lc.*, u.id as uid, u.email, u.role, u.owner_id FROM login_codes lc JOIN users u ON lc.user_id = u.id WHERE lc.phone=$1 AND lc.consumed_at IS NULL AND lc.expires_at > NOW() ORDER BY lc.created_at DESC LIMIT 1`, [p]); if (q.rowCount === 0) return res.status(400).json({ ok: false, error: "Inválido" }); const row = q.rows[0]; if (!(await bcrypt.compare(String(code), row.code_hash))) return res.status(400).json({ ok: false, error: "Incorrecto" }); await pool.query("UPDATE login_codes SET consumed_at=NOW() WHERE id=$1", [row.id]); await pool.query("UPDATE users SET is_verified=TRUE WHERE id=$1", [row.uid]); res.json({ ok: true, token: signToken({ id: row.uid, email: row.email, phone: p, role: row.role, owner_id: row.owner_id }) }); } catch (e) { res.status(500).json({ ok: false }); } +}); -
-
-
+app.post("/auth/login", async (req, res) => { + try { const { email, password } = req.body; const q = await pool.query("SELECT * FROM users WHERE email=$1", [email]); if (q.rowCount === 0) return res.status(401).json({ ok: false, error: "Datos incorrectos" }); let user = null; for (const u of q.rows) { if (await bcrypt.compare(password, u.password_hash)) { user = u; break; } } if (!user) return res.status(401).json({ ok: false, error: "Datos incorrectos" }); res.json({ ok: true, token: signToken(user) }); } catch(e) { res.status(500).json({ ok: false }); } +}); -
Msg
- - - - - \ No newline at end of file +const port = process.env.PORT || 3000; +autoUpdateDB().then(() => { app.listen(port, "0.0.0.0", () => console.log(`🚀 Server OK en puerto ${port}`)); }); \ No newline at end of file