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/licenses/get-managed.ts
Views: 687
1
/*
2
Get all licenses that the signed in user manages.
3
4
See docs in @cocalc/server/licenses/get-managed.ts
5
6
Returns [License1, License2, ...] on success or {error:'a message'} on failure.
7
For the fields in the License objects, see @cocalc/server/licenses/get-managed.ts
8
*/
9
10
import getManagedLicenses, {
11
License,
12
} from "@cocalc/server/licenses/get-managed";
13
import getAccountId from "lib/account/get-account";
14
import getParams from "lib/api/get-params";
15
16
import { apiRoute, apiRouteOperation } from "lib/api";
17
import {
18
GetManagedLicensesInputSchema,
19
GetManagedLicensesOutputSchema,
20
} from "lib/api/schema/licenses/get-managed";
21
22
async function handle(req, res) {
23
try {
24
res.json(await get(req));
25
} catch (err) {
26
res.json({ error: `${err.message}` });
27
return;
28
}
29
}
30
31
async function get(req): Promise<License[]> {
32
const account_id = await getAccountId(req);
33
if (account_id == null) {
34
return [];
35
}
36
const { limit, skip } = getParams(req);
37
return await getManagedLicenses(account_id, limit, skip);
38
}
39
40
export default apiRoute({
41
getManaged: apiRouteOperation({
42
method: "POST",
43
openApiOperation: {
44
tags: ["Licenses"],
45
},
46
})
47
.input({
48
contentType: "application/json",
49
body: GetManagedLicensesInputSchema,
50
})
51
.outputs([
52
{
53
status: 200,
54
contentType: "application/json",
55
body: GetManagedLicensesOutputSchema,
56
},
57
])
58
.handler(handle),
59
});
60
61