Path: blob/master/src/packages/next/lib/share/get-stars.ts
1450 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Get the public paths that the signed in user has starred.7*/89import getPool, { timeInSeconds } from "@cocalc/database/pool";10import { PublicPath } from "./types";11import getAccountId from "lib/account/get-account";1213export default async function getStars(14req // use to get account_id if necessary15): Promise<PublicPath[]> {16const account_id = await getAccountId(req);17if (!account_id) return []; // not signed in1819const pool = getPool("short");20const { rows } = await pool.query(21`SELECT id, path, url, description, ${timeInSeconds(22"last_edited"23)}, disabled, unlisted, authenticated,24counter::INT,25(SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=id) AS stars26FROM public_paths, public_path_stars WHERE27public_path_stars.account_id=$1 AND public_path_stars.public_path_id = public_paths.id ORDER BY public_paths.last_edited DESC`,28[account_id]29);30return rows;31}323334