g1t/apps/web/app/routes/workspace/statement-entries.ts

19 lines981 bytesCodeBlame
1import type { Route } from "./+types/statement-entries";
2import { billing } from "../../lib/services.server";
3import { getViewer } from "../../lib/session.server";
4
5/** One statement line's entries, 50 at a time, for the billing page to open. */
6export async function loader({ params, context, request }: Route.LoaderArgs) {
7 const query = new URL(request.url).searchParams;
8 const entries = await billing.statementEntries(params.owner, getViewer(context), {
9 month: query.get("month") ?? "",
10 kind: query.get("kind") ?? "",
11 day: query.get("day"),
12 project: query.get("project"),
13 before: query.get("before"),
14 });
15 // Said beside the line that asked. As a 200: a fetcher shows any other
16 // status as an error page in place of the whole billing page.
17 if (!entries.ok) return Response.json({ error: entries.error.message }, { headers: { "cache-control": "no-store" } });
18 return Response.json(entries.value, { headers: { "cache-control": "no-store" } });
19}