fix: handle post getAll when no table posts exists
This commit is contained in:
@@ -1,9 +1,20 @@
|
|||||||
import client from "../db/index.js";
|
import client from "../db/index.js";
|
||||||
|
|
||||||
export default class PostController {
|
export default class PostController {
|
||||||
static async getAll() {
|
static async getAll(options) {
|
||||||
const res = await client.query("SELECT * FROM posts");
|
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;
|
return res.rows;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async get(id) {
|
static async get(id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user