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/salesloft/money.ts
Views: 687
1
/*
2
Allows admins to get useful stats about a user's spending behavior.
3
This is the same data we put in salesloft about them.
4
*/
5
6
import { getMoneyData } from "@cocalc/server/salesloft/money";
7
import getAccountId from "lib/account/get-account";
8
import getParams from "lib/api/get-params";
9
import userIsInGroup from "@cocalc/server/accounts/is-in-group";
10
11
export default async function handle(req, res) {
12
try {
13
res.json(await get(req));
14
} catch (err) {
15
res.json({ error: `${err.message}` });
16
return;
17
}
18
}
19
20
async function get(req) {
21
const admin_account_id = await getAccountId(req);
22
if (admin_account_id == null) {
23
throw Error("must be signed in");
24
}
25
// This user MUST be an admin:
26
if (!(await userIsInGroup(admin_account_id, "admin"))) {
27
throw Error("only admins can use the salesloft/money endpoint");
28
}
29
30
const { account_id } = getParams(req);
31
32
return await getMoneyData(account_id);
33
}
34
35