36 lines
951 B
TypeScript
36 lines
951 B
TypeScript
import { apiGet, apiPost } from "./http";
|
|
import { TransactionsList, type TransactionsListT } from "./schemas";
|
|
|
|
export type TxQuery = {
|
|
from?: string; // YYYY-MM-DD
|
|
to?: string; // YYYY-MM-DD
|
|
kind?: "variable_spend" | "fixed_payment";
|
|
q?: string;
|
|
page?: number; // 1-based
|
|
limit?: number; // default 20
|
|
};
|
|
|
|
export type CreateTransactionPayload = {
|
|
kind: "variable_spend" | "fixed_payment";
|
|
amountCents: number;
|
|
occurredAtISO: string;
|
|
categoryId?: string;
|
|
planId?: string;
|
|
note?: string;
|
|
receiptUrl?: string;
|
|
isReconciled?: boolean;
|
|
};
|
|
|
|
export async function listTransactions(
|
|
params: TxQuery
|
|
): Promise<TransactionsListT> {
|
|
const data = await apiGet<unknown>("/transactions", params);
|
|
return TransactionsList.parse(data);
|
|
}
|
|
|
|
export async function createTransaction(
|
|
payload: CreateTransactionPayload
|
|
): Promise<{ id: string; nextDueOn?: string }> {
|
|
return await apiPost("/transactions", payload);
|
|
}
|