Path: blob/master/src/packages/next/pages/api/v2/salesloft/money.ts
1452 views
/*1Allows admins to get useful stats about a user's spending behavior.2This is the same data we put in salesloft about them.3*/45import { getMoneyData } from "@cocalc/server/salesloft/money";6import getAccountId from "lib/account/get-account";7import getParams from "lib/api/get-params";8import userIsInGroup from "@cocalc/server/accounts/is-in-group";910export default async function handle(req, res) {11try {12res.json(await get(req));13} catch (err) {14res.json({ error: `${err.message}` });15return;16}17}1819async function get(req) {20const admin_account_id = await getAccountId(req);21if (admin_account_id == null) {22throw Error("must be signed in");23}24// This user MUST be an admin:25if (!(await userIsInGroup(admin_account_id, "admin"))) {26throw Error("only admins can use the salesloft/money endpoint");27}2829const { account_id } = getParams(req);3031return await getMoneyData(account_id);32}333435