fix: handle post getAll when no table posts exists
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user