Actualizar server.js
This commit is contained in:
36
server.js
36
server.js
@@ -2705,43 +2705,7 @@ app.delete("/budgets/:id", authMiddleware, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// 🤖 API COLA DEL ROBOT (REEMPLAZO FIREBASE)
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
// 1. Enviar una orden al Robot
|
|
||||||
app.post("/robot/queue", authMiddleware, async (req, res) => {
|
|
||||||
try {
|
|
||||||
const { service_number, new_status, appointment_date, observation, inform_client } = req.body;
|
|
||||||
|
|
||||||
const q = await pool.query(`
|
|
||||||
INSERT INTO robot_queue (owner_id, service_number, new_status, appointment_date, observation, inform_client)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6) RETURNING id
|
|
||||||
`, [req.user.accountId, service_number, new_status, appointment_date || "", observation || "", inform_client || false]);
|
|
||||||
|
|
||||||
res.json({ ok: true, jobId: q.rows[0].id });
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error guardando en cola:", e);
|
|
||||||
res.status(500).json({ ok: false, error: e.message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2. Leer el estado de la cola (Monitor)
|
|
||||||
app.get("/robot/queue", authMiddleware, async (req, res) => {
|
|
||||||
try {
|
|
||||||
const q = await pool.query(`
|
|
||||||
SELECT id, service_number, status, error_msg, created_at
|
|
||||||
FROM robot_queue
|
|
||||||
WHERE owner_id = $1
|
|
||||||
ORDER BY created_at DESC
|
|
||||||
LIMIT 20
|
|
||||||
`, [req.user.accountId]);
|
|
||||||
|
|
||||||
res.json({ ok: true, jobs: q.rows });
|
|
||||||
} catch (e) {
|
|
||||||
res.status(500).json({ ok: false });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user