commenting unintuitive sql query

This commit is contained in:
Khalim Conn-Kowlessar 2026-04-22 10:10:34 +00:00
parent 4bbd973b6b
commit afdc8ec703

View file

@ -132,10 +132,16 @@ export async function GET(
)::float AS total_sap_uplift
FROM latest_plans lp
JOIN property p ON p.id = lp.property_id
-- Conditional filter: only restrict by original_sap_points when the toggle is on
-- AND the scenario has an EPC target. Written as an OR chain so Postgres evaluates
-- it as a single WHERE clause avoiding the need to dynamically build the query
-- string in application code (which would require string concatenation and risks
-- SQL injection). The OR short-circuits left-to-right: if the first or second
-- condition is true, the third is never evaluated, so all rows pass through.
WHERE (
${useOriginalBaseline} = false
OR ${minSap}::float IS NULL
OR p.original_sap_points < ${minSap}::float
${useOriginalBaseline} = false -- toggle off include everything
OR ${minSap}::float IS NULL -- no EPC target nothing to filter on
OR p.original_sap_points < ${minSap}::float -- actual filter
);
`);