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/purchases/email-statement.ts
Views: 687
1
/*
2
Email a specific statement to the user. Error if this statement has been emailed to this user
3
within the last 6 hours.
4
*/
5
6
import getAccountId from "lib/account/get-account";
7
import emailStatement from "@cocalc/server/purchases/statements/email-statement";
8
import getParams from "lib/api/get-params";
9
import { OkStatus } from "lib/api/status";
10
11
export default async function handle(req, res) {
12
try {
13
res.json(await get(req));
14
} catch (err) {
15
res.json({ error: `${err.message}` });
16
return;
17
}
18
}
19
20
async function get(req) {
21
const account_id = await getAccountId(req);
22
if (account_id == null) {
23
throw Error("must be signed in");
24
}
25
const { statement_id } = getParams(req);
26
await emailStatement({ account_id, statement_id });
27
return OkStatus;
28
}
29
30