Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/purchases/get-balance.ts
1454 views
1
/*
2
Get balance right now.
3
As a side effect, it updates the balance field of the accounts table.
4
*/
5
6
import getAccountId from "lib/account/get-account";
7
import getBalance from "@cocalc/server/purchases/get-balance";
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) {
19
const account_id = await getAccountId(req);
20
if (account_id == null) {
21
throw Error("must be signed in");
22
}
23
return await getBalance({ account_id });
24
}
25
26