"use strict";
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*
Get the public paths that the signed in user has starred.
*/
const pool_1 = __importStar(require("@cocalc/database/pool"));
const get_account_1 = __importDefault(require("lib/account/get-account"));
async function getStars(req //  use to get account_id if necessary
) {
    const account_id = await (0, get_account_1.default)(req);
    if (!account_id)
        return []; // not signed in
    const pool = (0, pool_1.default)("short");
    const { rows } = await pool.query(`SELECT id, path, url, description, ${(0, pool_1.timeInSeconds)("last_edited")}, disabled, unlisted, authenticated,
    counter::INT,
     (SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=id) AS stars
    FROM public_paths, public_path_stars WHERE
    public_path_stars.account_id=$1 AND public_path_stars.public_path_id = public_paths.id ORDER BY public_paths.last_edited DESC`, [account_id]);
    return rows;
}
exports.default = getStars;
//# sourceMappingURL=get-stars.js.map