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/database/postgres/site-license/public.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { PostgreSQL } from "../types";
7
import { query } from "../query";
8
import {
9
number_of_running_projects_using_license,
10
number_of_projects_with_license_applied,
11
} from "./analytics";
12
13
export async function site_license_public_info(
14
db: PostgreSQL,
15
license_id: string
16
): Promise<number> {
17
// Get information about the license itself:
18
const obj = await query({
19
db,
20
select: [
21
"title",
22
"description",
23
"expires",
24
"activates",
25
"upgrades",
26
"quota",
27
"run_limit",
28
"managers",
29
"subscription_id",
30
],
31
table: "site_licenses",
32
where: { id: license_id },
33
one: true,
34
});
35
if (!obj) throw Error(`no license with id ${license_id}`);
36
37
// Get number of runnings projects with this license applied.
38
obj.running = await number_of_running_projects_using_license(db, license_id);
39
// Get number of projects with this license applied (may not be running or actually using license).
40
obj.applied = await number_of_projects_with_license_applied(db, license_id);
41
42
return obj;
43
}
44
45