Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/src/packages/next/pages/api/v2/purchases/get-purchases.ts
Views: 923
/*1Let user get all of their purchases2*/34import getAccountId from "lib/account/get-account";5import getPurchases from "@cocalc/server/purchases/get-purchases";6import getParams from "lib/api/get-params";7import { apiRoute, apiRouteOperation } from "lib/api";8import {9GetPurchasesInputSchema,10GetPurchasesOutputSchema,11} from "lib/api/schema/purchases/get-purchases";12import throttle from "@cocalc/util/api/throttle";1314async function handle(req, res) {15try {16res.json(await get(req));17} catch (err) {18res.json({ error: `${err.message}` });19return;20}21}2223async function get(req) {24const account_id = await getAccountId(req);25if (!account_id) {26throw Error("must be signed in");27}28const {29limit,30offset,31service,32project_id,33group,34cutoff,35thisMonth,36day_statement_id,37month_statement_id,38no_statement,39compute_server_id,40} = getParams(req);41if (!compute_server_id) {42// for now we are only throttling when compute_server_id is NOT set. There are several cases -- course management etc43// where a client calls get-purchases for each compute server separately with group -- it's not much load.44throttle({45account_id,46endpoint: "purchases/get-purchases",47});48}49return await getPurchases({50cutoff,51thisMonth,52limit,53offset,54service,55account_id,56project_id,57group,58day_statement_id,59month_statement_id,60no_statement,61compute_server_id,62});63}6465export default apiRoute({66getPurchases: apiRouteOperation({67method: "POST",68openApiOperation: {69tags: ["Purchases"],70},71})72.input({73contentType: "application/json",74body: GetPurchasesInputSchema,75})76.outputs([77{78status: 200,79contentType: "application/json",80body: GetPurchasesOutputSchema,81},82])83.handler(handle),84});858687