CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/share/get-stars.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Get the public paths that the signed in user has starred.
8
*/
9
10
import getPool, { timeInSeconds } from "@cocalc/database/pool";
11
import { PublicPath } from "./types";
12
import getAccountId from "lib/account/get-account";
13
14
export default async function getStars(
15
req // use to get account_id if necessary
16
): Promise<PublicPath[]> {
17
const account_id = await getAccountId(req);
18
if (!account_id) return []; // not signed in
19
20
const pool = getPool("short");
21
const { rows } = await pool.query(
22
`SELECT id, path, url, description, ${timeInSeconds(
23
"last_edited"
24
)}, disabled, unlisted, authenticated,
25
counter::INT,
26
(SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=id) AS stars
27
FROM public_paths, public_path_stars WHERE
28
public_path_stars.account_id=$1 AND public_path_stars.public_path_id = public_paths.id ORDER BY public_paths.last_edited DESC`,
29
[account_id]
30
);
31
return rows;
32
}
33
34