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/get-purchases.ts
Views: 687
1
/*
2
Let user get all of their purchases
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import getPurchases from "@cocalc/server/purchases/get-purchases";
7
import getParams from "lib/api/get-params";
8
9
import { apiRoute, apiRouteOperation } from "lib/api";
10
import {
11
GetPurchasesInputSchema,
12
GetPurchasesOutputSchema,
13
} from "lib/api/schema/purchases/get-purchases";
14
15
async function handle(req, res) {
16
try {
17
res.json(await get(req));
18
} catch (err) {
19
res.json({ error: `${err.message}` });
20
return;
21
}
22
}
23
24
async function get(req) {
25
const account_id = await getAccountId(req);
26
if (!account_id) {
27
throw Error("must be signed in");
28
}
29
const {
30
limit,
31
offset,
32
service,
33
project_id,
34
group,
35
cutoff,
36
thisMonth,
37
day_statement_id,
38
month_statement_id,
39
no_statement,
40
} = getParams(req);
41
return await getPurchases({
42
cutoff,
43
thisMonth,
44
limit,
45
offset,
46
service,
47
account_id,
48
project_id,
49
group,
50
day_statement_id,
51
month_statement_id,
52
no_statement,
53
});
54
}
55
56
export default apiRoute({
57
getPurchases: apiRouteOperation({
58
method: "POST",
59
openApiOperation: {
60
tags: ["Purchases"],
61
},
62
})
63
.input({
64
contentType: "application/json",
65
body: GetPurchasesInputSchema,
66
})
67
.outputs([
68
{
69
status: 200,
70
contentType: "application/json",
71
body: GetPurchasesOutputSchema,
72
},
73
])
74
.handler(handle),
75
});
76
77