CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/owner/get-name.ts
Views: 687
1
// Get the name of an owner, i.e., an account_id or organization_id.
2
3
import getPool from "@cocalc/database/pool";
4
5
// Returns "" if owner doesn't have a name set.
6
export default async function getName(owner_id: string): Promise<string> {
7
const pool = getPool('medium');
8
9
for (const type of ["account", "organization"]) {
10
const result = await pool.query(
11
`SELECT name FROM ${type}s WHERE ${type}_id=$1`,
12
[owner_id]
13
);
14
if (result.rows.length > 0) {
15
return result.rows[0].name;
16
}
17
}
18
return "";
19
}
20
21