Give every year of a repeating period its own row

A repeating period was a single row that the planner expanded into one
window per year at read time, so no year had anywhere to differ from the
others. Editing one year rewrote them all, and removing a year in the
middle had to split the wish in two. Neither survives contact with the
thing this app is for: Easter moves, and the cheapest week is not the
same week every year.

Each year is now its own row, linked by a series id. Editing one year
touches one row; editing the series re-projects the rest from it.
Removing a year is one delete. The weekday snap is worked out once, when
the rows are made, and stored, so a row now says what it means rather
than being re-derived on every read. Recurrence stops being a stored
field and becomes what it always was in practice — an instruction at
create and update time; whether a period repeats is whether it belongs
to a series.

Migration 004 rebuilds the table and expands the existing rows, keeping
each original row as its first year so the days already planned against
it still point somewhere. A Feb 29 anchor recurring into a common year
used to raise out of the allocator; it clamps now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ei7gCZzdd751uZtPzb1Pep
This commit is contained in:
2026-09-19 15:53:25 +02:00
parent c6593062e3
commit 6d92b87bf3
43 changed files with 2735 additions and 638 deletions
+16 -5
View File
@@ -11,6 +11,7 @@ import { ApiRequestError } from '@/services/errors'
import type {
LoginRequest,
LeaveWishCreateRequest,
LeaveWishScope,
LeaveWishUpdateRequest,
ManualFetchRequest,
ParentalLeaveFetch,
@@ -241,9 +242,9 @@ interface RawLeaveWish {
window_end_day: number
target_weeks: number
target_days?: number | null
recurrence: 'yearly' | 'once'
first_year: number
last_year: number | null
series_id: string | null
priority: number
parent_mode: 'either' | 'both' | 'specific'
parent_personal_data_uuid: string | null
@@ -266,8 +267,8 @@ function toLeaveWish(raw: RawLeaveWish): LeaveWish {
windowEndDay: raw.window_end_day,
targetWeeks: raw.target_weeks,
targetDays: raw.target_days ?? null,
recurrence: raw.recurrence,
firstYear: raw.first_year,
seriesId: raw.series_id ?? null,
lastYear: raw.last_year,
priority: raw.priority,
parentMode: raw.parent_mode,
@@ -864,15 +865,20 @@ export async function createLeaveWish(payload: LeaveWishCreateRequest): Promise<
parent_mode: payload.parentMode ?? 'either',
parent_personal_data_uuid: payload.parentPersonalDataUuid ?? null,
window_mode: payload.windowMode ?? 'fixed',
series_id: payload.seriesId ?? null,
wants_dubbeldag: payload.wantsDubbeldag ?? false,
}),
})) as RawLeaveWish
return toLeaveWish(raw)
}
/** `scope` decides how far the edit reaches on a repeating wish — see
* `LeaveWishScope`. Omitted means "this year only", matching the backend's
* own default, so existing single-occurrence callers need no change. */
export async function updateLeaveWish(
id: string,
payload: LeaveWishUpdateRequest,
scope: LeaveWishScope = 'occurrence',
): Promise<LeaveWish> {
const body: Record<string, unknown> = {}
if (payload.childId !== undefined) body.child_id = payload.childId
@@ -895,15 +901,20 @@ export async function updateLeaveWish(
if (payload.windowMode !== undefined) body.window_mode = payload.windowMode
if (payload.wantsDubbeldag !== undefined) body.wants_dubbeldag = payload.wantsDubbeldag
const raw = (await apiFetch(`/leave-wishes/${id}`, {
const raw = (await apiFetch(`/leave-wishes/${id}?scope=${scope}`, {
method: 'PUT',
body: JSON.stringify(body),
})) as RawLeaveWish
return toLeaveWish(raw)
}
export async function deleteLeaveWish(id: string): Promise<void> {
return apiFetch(`/leave-wishes/${id}`, { method: 'DELETE' })
/** `scope: 'series'` removes every year of a repeating wish; the default
* removes just this one year's row. */
export async function deleteLeaveWish(
id: string,
scope: LeaveWishScope = 'occurrence',
): Promise<void> {
return apiFetch(`/leave-wishes/${id}?scope=${scope}`, { method: 'DELETE' })
}
/** Read-only preview of the planning engine's proposal — persists nothing. */