fiddy/apps/web/lib/client/entries.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

56 lines
1.7 KiB
TypeScript

import { fetchJson } from "@/lib/client/fetch-json";
import type { Entry } from "@/lib/shared/types";
export async function entriesList() {
return fetchJson<{ entries: Entry[] }>("/api/entries", { method: "GET" });
}
export async function entriesCreate(input: {
entryType: "SPENDING" | "INCOME";
amountDollars: number;
occurredAt: string;
necessity: "NECESSARY" | "BOTH" | "UNNECESSARY";
purchaseType: string;
notes?: string;
tags?: string[];
bucketId?: number | null;
}) {
return fetchJson<{ entry: Entry }>("/api/entries", {
method: "POST",
body: JSON.stringify(input)
});
}
export async function entriesUpdate(input: {
id: number;
entryType: "SPENDING" | "INCOME";
amountDollars: number;
occurredAt: string;
necessity: "NECESSARY" | "BOTH" | "UNNECESSARY";
purchaseType: string;
notes?: string;
tags?: string[];
bucketId?: number | null;
}) {
return fetchJson<{ entry: Entry }>(`/api/entries/${input.id}`, {
method: "PATCH",
body: JSON.stringify({
entryType: input.entryType,
amountDollars: input.amountDollars,
occurredAt: input.occurredAt,
necessity: input.necessity,
purchaseType: input.purchaseType,
notes: input.notes,
tags: input.tags,
bucketId: input.bucketId
})
});
}
export async function entriesDelete(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/entries/${numericId}`, { method: "DELETE" });
}