Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Build conditional payloads declaratively, not with stacked ifs
Assemble an object of all candidate fields, then filter by a whitelist and non-null check in one pass, instead of mutating the payload through a chain of if statements.
Bad example
| 1 | const p = { title, content }; |
| 2 | if (push.seoTitle && seo?.seoTitle) p.seoTitle = seo.seoTitle; |
| 3 | if (push.authorId && authorId) p.authorId = authorId; |
| 4 | // ...repeated per field |
Explanation (EN)
Repeated identical inclusion branches can drift, but a common filter must preserve each field's meaning.
Objašnjenje (HR)
Good example
| 1 | const optional = { seoTitle: seo?.seoTitle, authorId, categoryId }; |
| 2 | const filtered = Object.fromEntries( |
| 3 | Object.entries(optional).filter(([k, v]) => fieldsToPush[k] && v != null), |
| 4 | ); |
| 5 | await push({ title, content, ...filtered }); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Use a typed allowlist or schema to construct a payload when several fields share the same inclusion policy.
Exceptions / Tradeoffs (EN)
Fields can differ: zero/false/empty string may be valid, and null can mean clear in PATCH. Object.fromEntries can weaken type relationships; retain explicit branches where they express different field contracts.