mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
commenting unintuitive sql query
This commit is contained in:
parent
4bbd973b6b
commit
afdc8ec703
1 changed files with 9 additions and 3 deletions
|
|
@ -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
|
||||
);
|
||||
`);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue