diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-08 08:57:08 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-08 08:57:08 +0200 |
| commit | 4b2b964283075712de98743720ff3e31370ddc8e (patch) | |
| tree | 7200e83869dbd42d5f20318a07a6ca328e5ac59f /src/lib/server/services/validation.ts | |
| parent | 992e40835af1600a0961ec2454fb78ff43aec3c6 (diff) | |
Deduplicate routine actions and badges across project routes
- Share edit/complete/archive form actions in routine-actions.ts; route
servers become thin wrappers (strictest guard semantics in one place)
- Move parseFrequencyDays into validation.ts
- Extract ScoreBadge/StatusBadge components; use on project pages and
the home page instead of duplicated scoreClass/statusClass helpers
- Fix archiveProject calling the routine archive with the project id
Diffstat (limited to 'src/lib/server/services/validation.ts')
| -rw-r--r-- | src/lib/server/services/validation.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/server/services/validation.ts b/src/lib/server/services/validation.ts index a8cebd9..69820ea 100644 --- a/src/lib/server/services/validation.ts +++ b/src/lib/server/services/validation.ts @@ -1,3 +1,4 @@ +import { parseIntervalToDays } from '$lib/shared/routine-metrics'; import * as v from 'valibot'; export const IdSchema = v.pipe(v.number(), v.integer(), v.minValue(1)); @@ -43,3 +44,12 @@ export function parseOptionalNumber( if (!Number.isFinite(n)) return null; return n; } + +/** Parses an interval like '2w' into days; throws when the format is invalid. */ +export function parseFrequencyDays(value: FormDataEntryValue | null): number { + const days = parseIntervalToDays(value?.toString() ?? ''); + if (days === null) { + throw new Error('Invalid interval'); + } + return days; +} |
