Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/purchases/get-purchases.ts
Views: 687
/*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";78import { apiRoute, apiRouteOperation } from "lib/api";9import {10GetPurchasesInputSchema,11GetPurchasesOutputSchema,12} from "lib/api/schema/purchases/get-purchases";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,39} = getParams(req);40return await getPurchases({41cutoff,42thisMonth,43limit,44offset,45service,46account_id,47project_id,48group,49day_statement_id,50month_statement_id,51no_statement,52});53}5455export default apiRoute({56getPurchases: apiRouteOperation({57method: "POST",58openApiOperation: {59tags: ["Purchases"],60},61})62.input({63contentType: "application/json",64body: GetPurchasesInputSchema,65})66.outputs([67{68status: 200,69contentType: "application/json",70body: GetPurchasesOutputSchema,71},72])73.handler(handle),74});757677