fiddy/apps/web/lib/client/schedules.ts
Nico f8e426542d
Some checks failed
Build & Deploy Fiddy (Dokploy) / build (push) Has been cancelled
Build & Deploy Fiddy (Dokploy) / deploy (push) Has been cancelled
feat: implement schedules pivot, scheduler service, and dokploy deploy flow
2026-02-15 17:10:58 -08:00

43 lines
1.5 KiB
TypeScript

import { fetchJson } from "@/lib/client/fetch-json";
import type { Schedule, ScheduleEndCondition, ScheduleFrequency } from "@/lib/shared/types";
type ScheduleInput = {
entryType: "SPENDING" | "INCOME";
amountDollars: number;
necessity: "NECESSARY" | "BOTH" | "UNNECESSARY";
purchaseType: string;
notes?: string;
tags?: string[];
startsOn: string;
frequency: ScheduleFrequency;
intervalCount?: number;
endCondition?: ScheduleEndCondition;
endCount?: number | null;
endDate?: string | null;
};
export async function schedulesList() {
return fetchJson<{ schedules: Schedule[] }>("/api/schedules", { method: "GET" });
}
export async function schedulesCreate(input: ScheduleInput & { createEntryNow?: boolean }) {
return fetchJson<{ schedule: Schedule }>("/api/schedules", {
method: "POST",
body: JSON.stringify(input)
});
}
export async function schedulesUpdate(input: ScheduleInput & { id: number; nextRunOn?: string; isActive?: boolean }) {
return fetchJson<{ schedule: Schedule }>(`/api/schedules/${input.id}`, {
method: "PATCH",
body: JSON.stringify(input)
});
}
export async function schedulesDelete(input: { id: number | string }) {
const numericId = Number(input.id);
if (!Number.isFinite(numericId) || numericId <= 0)
return { error: { code: "INVALID_ID", message: "Invalid id" } } as const;
return fetchJson<{ ok: true }>(`/api/schedules/${numericId}`, { method: "DELETE" });
}