UNPKG

@cocalc/server

Version:

CoCalc server functionality: functions used by either the hub and the next.js server

35 lines (34 loc) 1.43 kB
"use strict"; /* Returns array of projects with a given license applied to them, including the following info: - project_id - title: of project - quota: what upgrades from license are being used right now, if any - last_edited: when project last_edited - collaborators: account_id's of collaborators on the project */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const pool_1 = __importDefault(require("@cocalc/database/pool")); const util_1 = require("@cocalc/database/postgres/util"); const misc_1 = require("@cocalc/util/misc"); async function getProjectsWithLicense(license_id) { if (!(0, misc_1.isValidUUID)(license_id)) { // importand due to sql injection throw Error("invalid license_id -- must be a uuid"); } const pool = (0, pool_1.default)("medium"); const { rows } = await pool.query(`SELECT project_id, title, site_license#>'{${license_id},quota}' as quota, ARRAY(SELECT jsonb_object_keys(users)) as collaborators, state#>'{state}' as state, last_edited FROM projects WHERE site_license ? '${license_id}' ORDER BY last_edited DESC`, []); (0, util_1.toEpoch)(rows, ["last_edited"]); return rows; } exports.default = getProjectsWithLicense; //# sourceMappingURL=get-projects-with-license.js.map