Path: blob/master/src/packages/next/pages/api/v2/purchases/stripe/get-open-payments.ts
1456 views
import getAccountId from "lib/account/get-account";1import { getAllOpenPayments } from "@cocalc/server/purchases/stripe/get-payments";2import throttle from "@cocalc/util/api/throttle";3import getParams from "lib/api/get-params";4import userIsInGroup from "@cocalc/server/accounts/is-in-group";56export default async function handle(req, res) {7try {8res.json(await get(req));9} catch (err) {10res.json({ error: `${err.message}` });11return;12}13}1415async function get(req) {16const account_id = await getAccountId(req);17if (account_id == null) {18throw Error("must be signed in");19}20throttle({21account_id,22endpoint: "purchases/stripe/get-open-payments",23});24const { user_account_id } = getParams(req);25if (user_account_id) {26// This user MUST be an admin:27if (!(await userIsInGroup(account_id, "admin"))) {28throw Error("only admins can get other user's open payments");29}30return await getAllOpenPayments(user_account_id);31}32return await getAllOpenPayments(account_id);33}343536