-
+const {
+ DATABASE_URL,
+ JWT_SECRET,
+ EVOLUTION_BASE_URL,
+ EVOLUTION_API_KEY,
+ EVOLUTION_INSTANCE,
+} = process.env;
-
-
+app.use(cors());
+app.use(express.json());
-
-
-
- - Servicios Activos -
-Gestiona las reparaciones y sus estados.
-
-
-
-
-
- | Fecha | -Cliente / Dirección | -Detalle | -Estado | -- |
|---|---|---|---|---|
| Cargando servicios... | ||||
-
+if (!DATABASE_URL || !JWT_SECRET) {
+ console.error("❌ ERROR FATAL: Faltan variables de entorno");
+ process.exit(1);
+}
-
+ 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 }); }
+});
-