final touches for beta skymoney (at least i think)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { request } from "./client";
|
||||
import { apiGet, apiPost } from "./http";
|
||||
import { TransactionsList, type TransactionsListT } from "./schemas";
|
||||
|
||||
export type TxQuery = {
|
||||
@@ -10,11 +10,26 @@ export type TxQuery = {
|
||||
limit?: number; // default 20
|
||||
};
|
||||
|
||||
export async function listTransactions(params: TxQuery): Promise<TransactionsListT> {
|
||||
const u = new URL("/api/transactions", location.origin);
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v !== undefined && v !== "") u.searchParams.set(k, String(v));
|
||||
}
|
||||
const data = await request<unknown>(u.pathname + "?" + u.searchParams.toString());
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user