diff --git a/internal/sla/queries.sql b/internal/sla/queries.sql index 935551f0..5b3a04d2 100644 --- a/internal/sla/queries.sql +++ b/internal/sla/queries.sql @@ -75,9 +75,9 @@ SET next_sla_deadline_at = CASE -- If resolved or closed, clear the deadline WHEN c.status_id IN (SELECT id FROM conversation_statuses WHERE name IN ('Resolved', 'Closed')) THEN NULL - -- If an external timestamp ($3) is provided (e.g. next_response), use the earliest of $3. - WHEN $3 IS NOT NULL THEN LEAST( - $3::TIMESTAMPTZ, + -- If an external timestamp ($2) is provided (e.g. next_response), use the earliest of $2. + WHEN $2::TIMESTAMPTZ IS NOT NULL THEN LEAST( + $2::TIMESTAMPTZ, CASE WHEN c.first_reply_at IS NOT NULL AND c.resolved_at IS NULL AND a.resolution_deadline_at IS NOT NULL THEN a.resolution_deadline_at WHEN c.first_reply_at IS NULL AND c.resolved_at IS NULL AND a.first_response_deadline_at IS NOT NULL THEN a.first_response_deadline_at @@ -86,7 +86,7 @@ SET next_sla_deadline_at = CASE END ) - -- No $3, + -- No $2, ELSE CASE WHEN c.first_reply_at IS NOT NULL AND c.resolved_at IS NULL AND a.resolution_deadline_at IS NOT NULL THEN a.resolution_deadline_at WHEN c.first_reply_at IS NULL AND c.resolved_at IS NULL AND a.first_response_deadline_at IS NOT NULL THEN a.first_response_deadline_at