UNPKG

@cocalc/database

Version:

CoCalc: code for working with our PostgreSQL database

35 lines 1.25 kB
"use strict"; /* * This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ Object.defineProperty(exports, "__esModule", { value: true }); exports.get_personal_user = void 0; const hof_1 = require("async-await-utils/hof"); const misc_1 = require("@cocalc/util/misc"); async function _get_personal_user(database) { // Get account_id of the one and only user, or if there is no user, create one and return its account_id. const result = await database.async_query({ query: "SELECT account_id FROM accounts WHERE created is not NULL ORDER BY created LIMIT 1", }); for (const row of result.rows) { return row.account_id; } // No results, so create THE account. const account_id = (0, misc_1.uuid)(); await database.async_query({ query: "INSERT INTO accounts", values: { account_id, first_name: "Your", last_name: "Name", created: new Date(), groups: ["admin"], }, }); return account_id; } exports.get_personal_user = (0, hof_1.reuseInFlight)(_get_personal_user, { createKey: () => "", }); //# sourceMappingURL=personal.js.map