render list of articles from backend

This commit is contained in:
2026-01-24 18:44:37 -06:00
parent c5e8faf9ed
commit d050127113
7 changed files with 148 additions and 59 deletions
+6 -6
View File
@@ -8,7 +8,7 @@ export const articlesRouter = express.Router();
articlesRouter.get("/getAllArticles", async (_, res: Response) => {
const resp = await db.select().from(articles);
res.json({ resp });
res.json(resp);
});
articlesRouter.get("/getArticle/:articleId", async (req: Request, res: Response) => {
@@ -17,7 +17,7 @@ articlesRouter.get("/getArticle/:articleId", async (req: Request, res: Response)
const resp = await db.select()
.from(articles)
.where(eq(articles.id, articleId));
res.json({ resp });
res.json(resp);
});
articlesRouter.get("/getArticleBySlug/:slug", async (req: Request, res: Response) => {
@@ -26,7 +26,7 @@ articlesRouter.get("/getArticleBySlug/:slug", async (req: Request, res: Response
const resp = await db.select()
.from(articles)
.where(eq(articles.slug, slug));
res.json({ resp });
res.json(resp);
});
articlesRouter.post("/postArticle", async (req: Request, res: Response) => {
@@ -36,7 +36,7 @@ articlesRouter.post("/postArticle", async (req: Request, res: Response) => {
...req.body,
slug: req.body.name.trim().toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, ''),
});
res.json({ resp });
res.json(resp);
});
articlesRouter.put("/putArticle/:articleId", async (req: Request, res: Response) => {
@@ -52,7 +52,7 @@ articlesRouter.put("/putArticle/:articleId", async (req: Request, res: Response)
date_published: req.body.article_status == "published" ? new Date(Date.now()) : null
})
.where(eq(articles.id, articleId));
res.json({ resp });
res.json(resp);
});
articlesRouter.delete("/deleteArticle/:articleId", async (req: Request, res: Response) => {
@@ -60,5 +60,5 @@ articlesRouter.delete("/deleteArticle/:articleId", async (req: Request, res: Res
const resp = await db.delete(articles)
.where(eq(articles.id, articleId));
res.json({ resp });
res.json(resp);
});