Fix: evitar duplicar servicio al convertir presupuesto dos veces
This commit is contained in:
@@ -5173,6 +5173,11 @@ app.post("/budgets/:id/convert", authMiddleware, async (req, res) => {
|
|||||||
if (bq.rowCount === 0) return res.status(404).json({ok: false});
|
if (bq.rowCount === 0) return res.status(404).json({ok: false});
|
||||||
const budget = bq.rows[0];
|
const budget = bq.rows[0];
|
||||||
|
|
||||||
|
// 🛑 Evitar conversiones duplicadas: si este presupuesto ya se convirtió antes en un servicio, no crear otro
|
||||||
|
if (budget.status === 'converted' || budget.status === 'paid') {
|
||||||
|
return res.status(409).json({ ok: false, error: "Este presupuesto ya fue convertido en un servicio anteriormente." });
|
||||||
|
}
|
||||||
|
|
||||||
// 🟢 Saber si ya estaba pagado antes de convertirlo
|
// 🟢 Saber si ya estaba pagado antes de convertirlo
|
||||||
const isAlreadyPaid = budget.status === 'paid';
|
const isAlreadyPaid = budget.status === 'paid';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user