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/billing/get-subscriptions.ts
Views: 687
1
/*
2
Get subscriptions for the signed in user.
3
*/
4
5
import getSubscriptions from "@cocalc/server/billing/get-subscriptions";
6
import getAccountId from "lib/account/get-account";
7
import getParams from "lib/api/get-params";
8
9
export default async function handle(req, res) {
10
try {
11
res.json(await get(req));
12
} catch (err) {
13
res.json({ error: `${err.message}` });
14
return;
15
}
16
}
17
18
async function get(req): Promise<object> {
19
const account_id = await getAccountId(req);
20
if (account_id == null) {
21
return [];
22
}
23
// these are defined at https://stripe.com/docs/api/pagination
24
// limit is between 1 and 100
25
// starting_after and ending_before are object id's
26
const { limit, starting_after, ending_before } = getParams(req);
27
return await getSubscriptions(account_id, {
28
limit,
29
starting_after,
30
ending_before,
31
});
32
}
33
34