Actualizar server.js
This commit is contained in:
41
server.js
41
server.js
@@ -2985,12 +2985,28 @@ app.delete("/budgets/:id", authMiddleware, async (req, res) => {
|
||||
// 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;
|
||||
// AÑADIDO: Recogemos el provider y el appointment_time
|
||||
const { provider, service_number, new_status, appointment_date, appointment_time, observation, inform_client } = req.body;
|
||||
|
||||
// Si no mandan provider (ej: App vieja), asumimos homeserve por retrocompatibilidad
|
||||
const finalProvider = provider || 'homeserve';
|
||||
|
||||
// IMPORTANTE: Nos aseguramos de que la tabla tiene la columna de la hora para Multiasistencia
|
||||
await pool.query(`ALTER TABLE robot_queue ADD COLUMN IF NOT EXISTS appointment_time TEXT;`).catch(() => {});
|
||||
|
||||
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]);
|
||||
INSERT INTO robot_queue (owner_id, provider, service_number, new_status, appointment_date, appointment_time, observation, inform_client)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id
|
||||
`, [
|
||||
req.user.accountId,
|
||||
finalProvider,
|
||||
service_number,
|
||||
new_status,
|
||||
appointment_date || "",
|
||||
appointment_time || "", // Nueva variable de hora
|
||||
observation || "",
|
||||
inform_client || false
|
||||
]);
|
||||
|
||||
res.json({ ok: true, jobId: q.rows[0].id });
|
||||
} catch (e) {
|
||||
@@ -2999,23 +3015,6 @@ app.post("/robot/queue", authMiddleware, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 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 });
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// 🔐 RECUPERAR CREDENCIALES
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user