"use strict";
/*
Get all projects that have a given license applied to them.  Signed in user
must be a manager of the given license so they are allowed access to this data.

See docs in @cocalc/server/licenses/get-projects-with-license.ts

Returns [Project1, Project2, ...] on success or {error:'a message'} on failure.
For the fields in the projects, see @cocalc/server/licenses/get-projects.ts
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const get_projects_with_license_1 = __importDefault(require("@cocalc/server/licenses/get-projects-with-license"));
const get_license_1 = require("@cocalc/server/licenses/get-license");
const get_account_1 = __importDefault(require("lib/account/get-account"));
const get_params_1 = __importDefault(require("lib/api/get-params"));
const misc_1 = require("@cocalc/util/misc");
async function handle(req, res) {
    try {
        res.json(await get(req));
    }
    catch (err) {
        res.json({ error: `${err.message}` });
        return;
    }
}
exports.default = handle;
async function get(req) {
    const account_id = await (0, get_account_1.default)(req);
    if (account_id == null) {
        throw Error("must be signed in as a manager of the license");
    }
    const { license_id } = (0, get_params_1.default)(req);
    if (!(0, misc_1.isValidUUID)(license_id)) {
        throw Error("license_id must be a valid uuid");
    }
    if (!(await (0, get_license_1.isManager)(license_id, account_id))) {
        throw Error("signed in user must be a manager of the license");
    }
    return await (0, get_projects_with_license_1.default)(license_id);
}
//# sourceMappingURL=get-projects-with-license.js.map