diff --git a/server.js b/server.js index a3bd4be..722de68 100644 --- a/server.js +++ b/server.js @@ -4769,6 +4769,25 @@ app.post("/budgets", authMiddleware, async (req, res) => { } }); +// Actualizar Presupuesto Existente +app.put("/budgets/:id", authMiddleware, async (req, res) => { + try { + const { client_phone, client_name, client_address, items, subtotal, tax, total } = req.body; + + const q = await pool.query( + "UPDATE budgets SET client_phone=$1, client_name=$2, client_address=$3, items=$4, subtotal=$5, tax=$6, total=$7 WHERE id=$8 AND owner_id=$9", + [client_phone, client_name, client_address, JSON.stringify(items), subtotal, tax, total, req.params.id, req.user.accountId] + ); + + if (q.rowCount === 0) return res.status(404).json({ ok: false, error: "Presupuesto no encontrado" }); + + res.json({ ok: true }); + } catch(e) { + console.error("Error al actualizar presupuesto:", e); + res.status(500).json({ ok: false, error: "Error en el servidor al actualizar" }); + } +}); + app.patch("/budgets/:id/status", authMiddleware, async (req, res) => { try { await pool.query("UPDATE budgets SET status=$1 WHERE id=$2 AND owner_id=$3", [req.body.status, req.params.id, req.user.accountId]);