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-purchases-admin.ts
Views: 687
1
/*
2
Let admin get all of the purchases for a specified user.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import getPurchases from "@cocalc/server/purchases/get-purchases";
7
import getParams from "lib/api/get-params";
8
import userIsInGroup from "@cocalc/server/accounts/is-in-group";
9
10
export default async function handle(req, res) {
11
try {
12
res.json(await get(req));
13
} catch (err) {
14
res.json({ error: `${err.message}` });
15
return;
16
}
17
}
18
19
async function get(req) {
20
const admin_account_id = await getAccountId(req);
21
if (admin_account_id == null) {
22
throw Error("must be signed in");
23
}
24
// This user MUST be an admin:
25
if (!(await userIsInGroup(admin_account_id, "admin"))) {
26
throw Error("only admins can use the get-purchases-admin endpoint");
27
}
28
29
const {
30
account_id,
31
limit,
32
offset,
33
service,
34
project_id,
35
group,
36
cutoff,
37
thisMonth,
38
day_statement_id,
39
month_statement_id,
40
no_statement,
41
includeName,
42
} = getParams(req);
43
44
return await getPurchases({
45
cutoff,
46
thisMonth,
47
limit,
48
offset,
49
service,
50
account_id,
51
project_id,
52
group,
53
day_statement_id,
54
month_statement_id,
55
no_statement,
56
includeName,
57
});
58
}
59
60