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