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/vouchers/charge-for-unpaid-vouchers.ts
Views: 687
1
import chargeForUnpaidVouchers from "@cocalc/server/vouchers/charge-for-unpaid-vouchers";
2
import getAccountId from "lib/account/get-account";
3
import userIsInGroup from "@cocalc/server/accounts/is-in-group";
4
5
export default async function handle(req, res) {
6
try {
7
const result = await doIt(req);
8
res.json({ ...result, success: true });
9
} catch (err) {
10
res.json({ error: `${err.message}` });
11
return;
12
}
13
}
14
15
async function doIt(req) {
16
const account_id = await getAccountId(req);
17
if (account_id == null) {
18
throw Error("must be signed in to charge for unpaid vouchers");
19
}
20
if (!(await userIsInGroup(account_id, "admin"))) {
21
throw Error("only admins can initiate the charge for unpaid vouchers");
22
}
23
24
return await chargeForUnpaidVouchers();
25
}
26
27