"use strict";
exports.id = 8450;
exports.ids = [8450];
exports.modules = {

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getOwner),
/* harmony export */   "g": () => (/* binding */ getOwnerName)
/* harmony export */ });
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17763);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_util_db_schema_name_rules__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(988772);
/* Get basic information about a user or organization
from the database.  This should be enough to render
a nice "homepage" for that user or organization.
*/ 

async function getOwner(owner) {
    if ((0,_cocalc_util_db_schema_name_rules__WEBPACK_IMPORTED_MODULE_1__.isReserved)(owner)) {
        // can't be so save us the trouble of consulting database; these are common
        // so this is a good win.
        throw Error("no such owner - reserved name");
    }
    const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default()("long");
    // Is it an account?
    let result = await pool.query("SELECT account_id FROM accounts WHERE LOWER(name)=$1", [
        owner.toLowerCase()
    ]);
    if (result.rows.length > 0) {
        return {
            type: "account",
            owner_id: result.rows[0].account_id
        };
    }
    // Is it an organization?
    result = await pool.query("SELECT title, description, organization_id FROM organizations WHERE LOWER(name)=$1", [
        owner.toLowerCase()
    ]);
    if (result.rows.length > 0) {
        return {
            type: "organization",
            owner_id: result.rows[0].organization_id
        };
    }
    throw Error(`no account or organization '${owner}'`);
};
async function getOwnerName(owner_id) {
    const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default()("long");
    let result = await pool.query("SELECT name FROM accounts WHERE account_id=$1", [
        owner_id
    ]);
    if (result.rows.length > 0) {
        const { name  } = result.rows[0];
        if (!name) return;
        return name;
    }
    result = await pool.query("SELECT name FROM organizations WHERE organization_id=$1", [
        owner_id
    ]);
    if (result.rows.length > 0) {
        const { name  } = result.rows[0];
        if (!name) return;
        return name;
    }
}


/***/ })

};
;