feat(web/m7-recurring-scans): scan-schedule API client + query

Adds ScanSchedule type, getScanSchedule / updateScanSchedule
against the new admin endpoints, createScanScheduleQuery (60s
staleTime; refetches on focus + after PATCH invalidation — no
polling).

New qk.scanSchedule() key follows the existing tuple pattern.
ScanScheduleUpdate uses optional fields so mode=off updates can
omit per-mode fields entirely (server normalizes anyway).

Vitest covers the GET path, PATCH with body, and the mode=off
minimal-body case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 22:28:22 -04:00
parent b650a121b5
commit 0cc3d6255d
3 changed files with 96 additions and 0 deletions
+37
View File
@@ -329,3 +329,40 @@ export function createCoverProvidersQuery() {
staleTime: 60_000
});
}
// Scan schedule -----------------------------------------------------------
export type ScanScheduleMode = 'off' | 'interval' | 'daily' | 'weekly';
export type ScanSchedule = {
mode: ScanScheduleMode;
interval_hours: number | null;
time_of_day: string | null; // 'HH:MM'
weekly_day: number | null; // 1..7 (Mon..Sun, ISO 8601)
next_scheduled_at: string | null; // RFC3339 ISO timestamp; null when mode='off'
};
export type ScanScheduleUpdate = {
mode: ScanScheduleMode;
interval_hours?: number | null;
time_of_day?: string | null;
weekly_day?: number | null;
};
export async function getScanSchedule(): Promise<ScanSchedule> {
return api.get<ScanSchedule>('/api/admin/scan/schedule');
}
export async function updateScanSchedule(patch: ScanScheduleUpdate): Promise<ScanSchedule> {
return api.patch<ScanSchedule>('/api/admin/scan/schedule', patch);
}
// Settings rarely change in operator time. 60s staleTime; refetches
// on window focus + after any PATCH invalidation — no polling.
export function createScanScheduleQuery() {
return createQuery({
queryKey: qk.scanSchedule(),
queryFn: getScanSchedule,
staleTime: 60_000
});
}