import getPool, { timeInSeconds } from "@cocalc/database/pool";
import { PublicPath } from "./types";
import getAccountId from "lib/account/get-account";
export default async function getStars(
req
): Promise<PublicPath[]> {
const account_id = await getAccountId(req);
if (!account_id) return [];
const pool = getPool("short");
const { rows } = await pool.query(
`SELECT id, path, url, description, ${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;
}