| 1 | import type { Route } from "./+types/statement-entries"; |
| 2 | import { billing } from "../../lib/services.server"; |
| 3 | import { getViewer } from "../../lib/session.server"; |
| 4 | |
| 5 | /** One statement line's entries, 50 at a time, for the billing page to open. */ |
| 6 | export 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 | } |