Path: blob/master/src/packages/next/pages/api/v2/vouchers/recent-vouchers.ts
1452 views
/*1Get recent purchases.2*/34import type { Voucher } from "@cocalc/util/db-schema/vouchers";5import getRecentlyCreatedVouchers from "@cocalc/server/vouchers/recent-vouchers";6import getAccountId from "lib/account/get-account";7import getParams from "lib/api/get-params";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): Promise<Voucher[]> {19const account_id = await getAccountId(req);20if (account_id == null) {21throw Error("must be signed in to get shopping cart information");22}23// recent = postgresql time, e.g., "1 day". Can be omitted, in which case default is "1 week".24const { recent } = getParams(req);25return await getRecentlyCreatedVouchers({ account_id, recent });26}272829