feat(vacay): read and write the leave year over its own window (#737)

Adds GET/PUT /addons/vacay/year-settings and makes the reads window-aware, so
the backend from the previous commit is actually reachable.

Entries and shared calendars now load over the caller's window instead of a
date prefix — a shifted year spans two calendar years and the prefix silently
dropped the second half. Reads are month-aligned (the grid draws month cards),
while entitlement stays day-exact; the two coincide for every window starting
on the 1st, which is all of calendar. deleteYear clears entries per author over
that author's period, and company holidays only over the range every member
shares, so one member deleting a period cannot reach into another's live one.
getStats reports the window it counted, and getOwnPlan seeds the period today
falls into rather than the calendar year.

A start day the month cannot have (Feb 29 from a hire date, a stored Feb 31)
is clamped to one every year has — otherwise the boundary string matches no
date and the whole window slides. Anniversary before a hire date is entered
resolves to the calendar year instead of borrowing a month a previous fiscal
setting left behind.

MCP reads pass their user through; without one the range stays the plain
calendar year, so plan-scoped callers are unchanged.
This commit is contained in:
Maurice
2026-07-25 11:50:22 +02:00
committed by Maurice
parent 2672a7a741
commit 9d93ed95bf
8 changed files with 200 additions and 20 deletions
+26
View File
@@ -3,6 +3,7 @@ import {
vacayInviteRequestSchema,
vacayToggleEntryRequestSchema,
vacayAddYearRequestSchema,
vacayYearSettingsRequestSchema,
} from './vacay.schema';
import { describe, it, expect } from 'vitest';
@@ -41,6 +42,31 @@ describe('vacayToggleEntryRequestSchema', () => {
});
});
describe('vacayYearSettingsRequestSchema', () => {
it('requires a known year type; the month/day/hire_date parts are optional', () => {
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'calendar' }).success).toBe(true);
expect(
vacayYearSettingsRequestSchema.safeParse({ year_type: 'fiscal', year_start_month: 7, year_start_day: 1 }).success,
).toBe(true);
expect(
vacayYearSettingsRequestSchema.safeParse({ year_type: 'anniversary', hire_date: '2019-09-16' }).success,
).toBe(true);
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'quarterly' }).success).toBe(false);
expect(vacayYearSettingsRequestSchema.safeParse({}).success).toBe(false);
});
it('rejects an out-of-range month or day', () => {
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'fiscal', year_start_month: 13 }).success).toBe(false);
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'fiscal', year_start_month: 0 }).success).toBe(false);
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'fiscal', year_start_day: 32 }).success).toBe(false);
});
it('takes a null hire_date but not a malformed one', () => {
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'anniversary', hire_date: null }).success).toBe(true);
expect(vacayYearSettingsRequestSchema.safeParse({ year_type: 'anniversary', hire_date: '16.09.2019' }).success).toBe(false);
});
});
describe('vacayAddYearRequestSchema', () => {
it('accepts a numeric or string year', () => {
expect(vacayAddYearRequestSchema.safeParse({ year: 2027 }).success).toBe(true);
+11
View File
@@ -57,6 +57,17 @@ export const vacayToggleEntryRequestSchema = z.object({
});
export type VacayToggleEntryRequest = z.infer<typeof vacayToggleEntryRequestSchema>;
// Configurable vacation year (#737): the leave-year window is per user, not per
// plan. 'calendar' is the unchanged Jan–Dec default, 'fiscal' starts on the given
// month/day, 'anniversary' on the month/day of the hire date.
export const vacayYearSettingsRequestSchema = z.object({
year_type: z.enum(['calendar', 'fiscal', 'anniversary']),
year_start_month: z.number().int().min(1).max(12).optional(),
year_start_day: z.number().int().min(1).max(31).optional(),
hire_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable().optional(),
});
export type VacayYearSettingsRequest = z.infer<typeof vacayYearSettingsRequestSchema>;
export const vacayCompanyHolidayRequestSchema = z.object({
date: z.string(),
note: z.string().optional(),