Path: blob/master/src/packages/next/lib/project/get-owner.ts
1450 views
import getPool from "@cocalc/database/pool";12// Returns account_id or organization_id of the owner of this project.3export default async function getOwner(project_id: string): Promise<string> {4const pool = getPool("minutes"); // we don't even have a way to change the owner ever in cocalc.56// TODO: this seems *really* stupid/inefficient in general, e.g., what if7// there are 1000 users? I don't know JSONB PostgreSQL enough to come up8// with a better query...9const result = await pool.query(10"SELECT users FROM projects WHERE project_id=$1",11[project_id]12);13if (result.rows.length == 0) {14throw Error(`no project with id ${project_id}`);15}16const { users } = result.rows[0] ?? {};17for (const account_id in users) {18if (users[account_id].group == "owner") {19return account_id;20}21}22throw Error(`project ${project_id} has no owner`);23}242526