"use strict";
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"));
// Returns account_id or organization_id of the owner of this project.
async function getOwner(project_id) {
    const pool = (0, pool_1.default)("minutes"); // we don't even have a way to change the owner ever in cocalc.
    // TODO: this seems *really* stupid/inefficient in general, e.g., what if
    // there are 1000 users?  I don't know JSONB PostgreSQL enough to come up
    // with a better query...
    const result = await pool.query("SELECT users FROM projects WHERE project_id=$1", [project_id]);
    if (result.rows.length == 0) {
        throw Error(`no project with id ${project_id}`);
    }
    const { users } = result.rows[0] ?? {};
    for (const account_id in users) {
        if (users[account_id].group == "owner") {
            return account_id;
        }
    }
    throw Error(`project ${project_id} has no owner`);
}
exports.default = getOwner;
//# sourceMappingURL=get-owner.js.map