You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(billing): lastResetAt + archivedAt schema + meter cap (PR-N8) (#3557)
* feat(billing): lastResetAt + archivedAt schema + meter cap (PR-N8)
P2.8 + P2.9 + P2.12 — robustness pass on the billing surface.
- P2.8: Subscription gains lastResetAt field. New repository method
findAllDueForResetByLastReset(now) replaces the 7-day window query
(resilient to scheduler delays beyond a week). resetAllDue persists
lastResetAt after each successful resetWeek. Legacy findAllDueForReset
kept and marked @deprecated for backward compat.
- P2.9: BillingUsage Mongoose + Zod schema declares archivedAt: Date|null.
archiveOtherWeeks() now queries by archivedAt: null instead of
$exists: false, matching the schema-default behavior. Without this
the field was silently stripped on write per Mongoose strict mode.
- P2.12: meter.service.attribute() applies maxUnitsPerOperation as a
clamp+warn before incrementMeter. Feature breakdown is rescaled
proportionally so persisted bucket totals stay consistent with
meterUsed.
Also updates scripts/tests/billing.cron.weeklyReset.unit.tests.js to mock
the new findAllDueForResetByLastReset + updateLastResetAt methods.
* fix(billing): capBreakdown — proportional rescaling + Object.create(null) + isCapped var
- Replace greedy strategy with proportional rescaling (ratio × floor + remainder
distributed to largest buckets) so breakdown buckets always sum to cappedUnits
exactly, matching the 'rescaled proportionally' intent in the PR description.
- Use Object.create(null) for cappedBreakdown to prevent prototype pollution
(Codacy HIGH risk).
- Extract isCapped boolean to eliminate the redundant cappedUnits < totalUnits
double-check (Codacy LOW risk).
- Pass originalTotal as a third arg to capBreakdown from attribute().
- Add 3 direct unit tests for capBreakdown (proportional multi-key, floor
remainder distribution, empty breakdown) as flagged missing by Codacy.
0 commit comments