mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
Targets could only be committed weekly, monthly, quarterly or yearly, so a figure the business quotes per half-year or per 90 days had to be split by hand into buckets it was never expressed in. The reports already re-gather a target into whatever grain the viewer asks for; this just lets the plan be entered at the grain it was agreed in. Adds day, half-year, nine-month and 90-day, matching the report units added alongside. normalisePeriodStart snaps each to its block start with the same calendar-year anchoring the SQL uses — Jan/Jul for half-years, Jan/Oct for nine-months, days 1/91/181/271 for 90-day blocks, including the same cap on the fourth block so late December does not snap into a stub of its own. That agreement is the load-bearing part. The unique index is keyed on period_start, and a target snapped to a boundary the report does not bucket on is a plan measured against a period that does not exist. The two halves live in different files and different languages, so the spec pins the boundaries rather than trusting them to stay in step. Adds operations-targets.service.spec.ts, which the module had none of: every period type, idempotency, the leap year, and the block-four cap.