cg / hackerproducts

63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / lib / comments.ts

src/lib/comments.ts · 33 lines · 679 B← back to folder
1import { query, isDatabaseConfigured } from "@/db";
2
3export interface ProductComment {
4 id: string;
5 product_id: string;
6 user_id: string;
7 username: string;
8 body: string;
9 created_at: string;
10}
11
12export async function listCommentsForProduct(productId: string): Promise<ProductComment[]> {
13 if (!isDatabaseConfigured()) return [];
14
15 const res = await query<ProductComment>(
16 `SELECT
17 c.id,
18 c.product_id,
19 c.user_id,
20 u.username,
21 c.body,
22 c.created_at
23 FROM comments c
24 JOIN users u ON u.id = c.user_id
25 WHERE c.product_id = $1
26 ORDER BY c.created_at ASC
27 LIMIT 200`,
28 [productId]
29 );
30
31 return res.rows;
32}
33
cg / hackerproducts — hacker products