Improve production plan operations

This commit is contained in:
Cauê Faleiros
2026-08-27 19:38:08 -03:00
parent ef29365932
commit 2b7c132300
2 changed files with 48 additions and 21 deletions

View File

@@ -900,9 +900,9 @@ const updateProductionPlanStatus = async (id, status) => {
try {
await client.query('BEGIN');
const planResult = await client.query(`
UPDATE production_plans
SET status = $1,
completed_at = CASE WHEN $1 = 'finished' THEN COALESCE(completed_at, CURRENT_TIMESTAMP) ELSE NULL END,
UPDATE production_plans
SET status = $1::text,
completed_at = CASE WHEN $1::text = 'finished' THEN COALESCE(completed_at, CURRENT_TIMESTAMP) ELSE NULL END,
updated_at = CURRENT_TIMESTAMP
WHERE id = $2
RETURNING id;
@@ -913,9 +913,9 @@ const updateProductionPlanStatus = async (id, status) => {
throw error;
}
await client.query(`
UPDATE production_orders
SET status = $1,
completed_date = CASE WHEN $1 = 'finished' THEN COALESCE(completed_date, CURRENT_DATE) ELSE completed_date END,
UPDATE production_orders
SET status = $1::text,
completed_date = CASE WHEN $1::text = 'finished' THEN COALESCE(completed_date, CURRENT_DATE) ELSE completed_date END,
updated_at = CURRENT_TIMESTAMP
WHERE production_plan_id = $2
AND status NOT IN ('finished', 'canceled');