Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: Sequelize
databasequery-buildingdefensive
Only add truthy filters to a database query
Build where-clauses by conditionally including parameters; do not forward undefined/empty values into the query so the function stays correct and standalone regardless of upstream validation.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const where = { |
| 2 | category: params.category, |
| 3 | region: params.region, // may be undefined, leaks into query |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const where: WhereOptions = {}; |
| 2 | if (params.category) where.category = params.category; |
| 3 | if (params.region) where.region = params.region; |
Explanation (EN)
Objašnjenje (HR)