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/set-quota.ts
Views: 687
1
/*
2
Let user set one of their purchase quotas.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import getParams from "lib/api/get-params";
7
import {
8
setPurchaseQuota,
9
getPurchaseQuotas,
10
PurchaseQuotas,
11
} from "@cocalc/server/purchases/purchase-quotas";
12
13
export default async function handle(req, res) {
14
try {
15
res.json(await get(req));
16
} catch (err) {
17
res.json({ error: `${err.message}` });
18
return;
19
}
20
}
21
22
async function get(req): Promise<PurchaseQuotas> {
23
const account_id = await getAccountId(req);
24
if (account_id == null) {
25
throw Error("must be signed in");
26
}
27
const { service, value } = getParams(req);
28
await setPurchaseQuota({ account_id, service, value: parseFloat(value) });
29
// it worked, so we return the new quotas
30
return await getPurchaseQuotas(account_id);
31
}
32
33