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-projects.ts
Views: 687
1
/*
2
Get all projects signed in user collaborates on
3
that have at least one license applied to them.
4
5
See docs in @cocalc/server/licenses/get-projects.ts
6
7
Returns [Project1, Project2, ...] on success or {error:'a message'} on failure.
8
For the fields in the projects, see @cocalc/server/licenses/get-projects.ts
9
*/
10
11
import getLicensedProjects, {
12
Project,
13
} from "@cocalc/server/licenses/get-projects";
14
import getAccountId from "lib/account/get-account";
15
16
export default async function handle(req, res) {
17
try {
18
res.json(await get(req));
19
} catch (err) {
20
res.json({ error: `${err.message}` });
21
return;
22
}
23
}
24
25
async function get(req): Promise<Project[]> {
26
const account_id = await getAccountId(req);
27
if (account_id == null) {
28
return [];
29
}
30
return await getLicensedProjects(account_id);
31
}
32
33