Path: blob/master/src/packages/next/pages/api/v2/purchases/set-quota.ts
1454 views
/*1Let user set one of their purchase quotas.2*/34import getAccountId from "lib/account/get-account";5import getParams from "lib/api/get-params";6import {7setPurchaseQuota,8getPurchaseQuotas,9PurchaseQuotas,10} from "@cocalc/server/purchases/purchase-quotas";1112export default async function handle(req, res) {13try {14res.json(await get(req));15} catch (err) {16res.json({ error: `${err.message}` });17return;18}19}2021async function get(req): Promise<PurchaseQuotas> {22const account_id = await getAccountId(req);23if (account_id == null) {24throw Error("must be signed in");25}26const { service, value } = getParams(req);27await setPurchaseQuota({ account_id, service, value: parseFloat(value) });28// it worked, so we return the new quotas29return await getPurchaseQuotas(account_id);30}313233