"use strict";
(() => {
var exports = {};
exports.id = 3360;
exports.ids = [3360];
exports.modules = {

/***/ 439491:
/***/ ((module) => {

module.exports = require("assert");

/***/ }),

/***/ 714300:
/***/ ((module) => {

module.exports = require("buffer");

/***/ }),

/***/ 706113:
/***/ ((module) => {

module.exports = require("crypto");

/***/ }),

/***/ 809523:
/***/ ((module) => {

module.exports = require("dns");

/***/ }),

/***/ 582361:
/***/ ((module) => {

module.exports = require("events");

/***/ }),

/***/ 657147:
/***/ ((module) => {

module.exports = require("fs");

/***/ }),

/***/ 113685:
/***/ ((module) => {

module.exports = require("http");

/***/ }),

/***/ 241808:
/***/ ((module) => {

module.exports = require("net");

/***/ }),

/***/ 822037:
/***/ ((module) => {

module.exports = require("os");

/***/ }),

/***/ 371017:
/***/ ((module) => {

module.exports = require("path");

/***/ }),

/***/ 677282:
/***/ ((module) => {

module.exports = require("process");

/***/ }),

/***/ 12781:
/***/ ((module) => {

module.exports = require("stream");

/***/ }),

/***/ 371576:
/***/ ((module) => {

module.exports = require("string_decoder");

/***/ }),

/***/ 924404:
/***/ ((module) => {

module.exports = require("tls");

/***/ }),

/***/ 76224:
/***/ ((module) => {

module.exports = require("tty");

/***/ }),

/***/ 257310:
/***/ ((module) => {

module.exports = require("url");

/***/ }),

/***/ 473837:
/***/ ((module) => {

module.exports = require("util");

/***/ }),

/***/ 160213:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ handle)
/* harmony export */ });
/* harmony import */ var _cocalc_server_licenses_get_projects_with_license__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(142501);
/* harmony import */ var _cocalc_server_licenses_get_projects_with_license__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_licenses_get_projects_with_license__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_server_licenses_get_license__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(742626);
/* harmony import */ var _cocalc_server_licenses_get_license__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_licenses_get_license__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var lib_account_get_account__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(559459);
/* harmony import */ var lib_api_get_params__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(26438);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(854006);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3__);
/*
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
*/ 




async function handle(req, res) {
    try {
        res.json(await get(req));
    } catch (err) {
        res.json({
            error: `${err.message}`
        });
        return;
    }
}
async function get(req) {
    const account_id = await (0,lib_account_get_account__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)(req);
    if (account_id == null) {
        throw Error("must be signed in as a manager of the license");
    }
    const { license_id  } = (0,lib_api_get_params__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)(req);
    if (!(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3__.isValidUUID)(license_id)) {
        throw Error("license_id must be a valid uuid");
    }
    if (!await (0,_cocalc_server_licenses_get_license__WEBPACK_IMPORTED_MODULE_1__.isManager)(license_id, account_id)) {
        throw Error("signed in user must be a manager of the license");
    }
    return await _cocalc_server_licenses_get_projects_with_license__WEBPACK_IMPORTED_MODULE_0___default()(license_id);
}


/***/ }),

/***/ 142501:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


/*
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(__webpack_require__(541808));
const util_1 = __webpack_require__(863563);
const misc_1 = __webpack_require__(854006);
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

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [8180,2921,9557,5245,6652,1808,4006,8312,5710,9459,4181,4012,3563,7596], () => (__webpack_exec__(160213)));
module.exports = __webpack_exports__;

})();