Added reading profile endpoint

This commit is contained in:
Sven laptop
2026-07-24 23:50:33 +02:00
parent 9e56f00c1e
commit eaeb0a29bc
7 changed files with 45 additions and 5 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ const path = require("path");
async function getPosts(req, res, ownOnly) {
try {
const query = ownOnly
? "SELECT id, title, text, author_id, image_link FROM posts WHERE author_id = $1"
: "SELECT id, title, text, author_id, image_link FROM posts";
? "SELECT p.id, p.title, p.text, p.author_id, people.username AS author_username, p.image_link, p.created_at FROM posts p LEFT JOIN people ON people.id = p.author_id WHERE p.author_id = $1"
: "SELECT p.id, p.title, p.text, p.author_id, people.username AS author_username, p.image_link, p.created_at FROM posts p LEFT JOIN people ON people.id = p.author_id";
const values = ownOnly ? [req.user.id] : [];
const { rows } = await pool.query(query, values);
res.status(200).json(rows);