Path: blob/master/src/packages/next/pages/api/v2/purchases/get-balance-admin.ts
1454 views
/*1Allows admins to get balance for a specific user.2*/34import getBalance from "@cocalc/server/purchases/get-balance";5import getAccountId from "lib/account/get-account";6import getParams from "lib/api/get-params";7import userIsInGroup from "@cocalc/server/accounts/is-in-group";89export default async function handle(req, res) {10try {11res.json(await get(req));12} catch (err) {13res.json({ error: `${err.message}` });14return;15}16}1718async function get(req) {19const admin_account_id = await getAccountId(req);20if (admin_account_id == null) {21throw Error("must be signed in");22}23// This user MUST be an admin:24if (!(await userIsInGroup(admin_account_id, "admin"))) {25throw Error("only admins can use the get-balance-admin endpoint");26}2728const { account_id } = getParams(req);2930return await getBalance({ account_id });31}323334