fix: handle post getAll when no table posts exists

This commit is contained in:
2026-03-13 14:28:17 +01:00
parent 5c42fb7f41
commit 65a55300a1

View File

@@ -1,9 +1,20 @@
import client from "../db/index.js";
export default class PostController {
static async getAll() {
const res = await client.query("SELECT * FROM posts");
return res.rows;
static async getAll(options) {
let queryText = "SELECT * FROM posts";
if (options && options.order === "asc") {
queryText += ' ORDER BY created_at DESC';
}
try {
const res = await client.query(queryText);
return res.rows;
} catch (err) {
console.log(err);
return [];
}
}
static async get(id) {