CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/vouchers/recent-vouchers.ts
Views: 687
1
/*
2
Get recent purchases.
3
*/
4
5
import type { Voucher } from "@cocalc/util/db-schema/vouchers";
6
import getRecentlyCreatedVouchers from "@cocalc/server/vouchers/recent-vouchers";
7
import getAccountId from "lib/account/get-account";
8
import getParams from "lib/api/get-params";
9
10
export default async function handle(req, res) {
11
try {
12
res.json(await get(req));
13
} catch (err) {
14
res.json({ error: `${err.message}` });
15
return;
16
}
17
}
18
19
async function get(req): Promise<Voucher[]> {
20
const account_id = await getAccountId(req);
21
if (account_id == null) {
22
throw Error("must be signed in to get shopping cart information");
23
}
24
// recent = postgresql time, e.g., "1 day". Can be omitted, in which case default is "1 week".
25
const { recent } = getParams(req);
26
return await getRecentlyCreatedVouchers({ account_id, recent });
27
}
28
29