CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/purchases/get-statements.ts
Views: 687
1
/*
2
Let user get all of their statements.
3
4
- interval -- 'day' or 'month'.
5
*/
6
7
import getAccountId from "lib/account/get-account";
8
import getStatements from "@cocalc/server/purchases/statements/get-statements";
9
import getParams from "lib/api/get-params";
10
11
export default async function handle(req, res) {
12
try {
13
res.json(await get(req));
14
} catch (err) {
15
res.json({ error: `${err.message}` });
16
return;
17
}
18
}
19
20
async function get(req) {
21
const account_id = await getAccountId(req);
22
if (account_id == null) {
23
throw Error("must be signed in");
24
}
25
const { limit, offset, interval } = getParams(req);
26
if (interval != "day" && interval != "month") {
27
throw Error("interval must be 'day' or 'month'");
28
}
29
return await getStatements({
30
limit,
31
offset,
32
account_id,
33
interval,
34
});
35
}
36
37