Path: blob/master/src/packages/next/pages/api/v2/purchases/get-purchases-admin.ts
1454 views
/*1Let admin get all of the purchases for a specified user.2*/34import getAccountId from "lib/account/get-account";5import getPurchases from "@cocalc/server/purchases/get-purchases";6import getParams from "lib/api/get-params";7import userIsInGroup from "@cocalc/server/accounts/is-in-group";8import throttle from "@cocalc/util/api/throttle";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 get-purchases-admin endpoint");27}28throttle({29account_id: admin_account_id,30endpoint: "purchases/get-purchases-admin",31});3233const {34account_id,35limit,36offset,37service,38project_id,39group,40cutoff,41thisMonth,42day_statement_id,43month_statement_id,44no_statement,45includeName,46} = getParams(req);4748return await getPurchases({49cutoff,50thisMonth,51limit,52offset,53service,54account_id,55project_id,56group,57day_statement_id,58month_statement_id,59no_statement,60includeName,61});62}636465