UNPKG

@cocalc/database

Version:

CoCalc: code for working with our PostgreSQL database

50 lines (48 loc) 1.98 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_all_public_paths = exports.unlist_all_public_paths = void 0; /* Queries related to public_paths. Probably more need to be rewritten and moved here... */ const async_utils_1 = require("@cocalc/util/async-utils"); const query_1 = require("./query"); const misc_1 = require("@cocalc/util/misc"); /* Unlist all public paths on all projects that the given account is a collaborator on. If is_owner is true (the default), only projects the account_id is the owner of are considered. This is not written to be optimally fast since it should barely ever get used. */ async function unlist_all_public_paths(db, account_id, is_owner = true) { const project_ids = await (0, async_utils_1.callback2)(db.get_project_ids_with_user, { account_id, is_owner, }); await (0, query_1.query)({ db, query: "UPDATE public_paths SET unlisted=true", where: { "project_id = ANY($)": project_ids }, }); } exports.unlist_all_public_paths = unlist_all_public_paths; async function get_all_public_paths(db, account_id) { if (!(0, misc_1.is_valid_uuid_string)(account_id)) { throw Error(`account_id="${account_id}" must be a valid uuid`); } return await (0, query_1.query)({ db, query: `SELECT pp.id, pp.project_id, pp.path, pp.description, pp.disabled, pp.authenticated, pp.unlisted, pp.license, pp.last_edited, pp.created, pp.last_saved, pp.counter, pp.compute_image FROM public_paths AS pp, projects WHERE pp.project_id = projects.project_id AND projects.users ? '${account_id}' AND projects.last_active ? '${account_id}' ORDER BY pp.last_edited DESC`, }); } exports.get_all_public_paths = get_all_public_paths; //# sourceMappingURL=public-paths.js.map