22 lines
827 B
JavaScript
22 lines
827 B
JavaScript
const express = require("express");
|
|
const auth = require("../../logins/middlewares/auth");
|
|
const Categories = require("../models/Categories");
|
|
const { getBlogsWithCategory, getCategoryWithParams, getBlogs } = require("../middlewares/query");
|
|
const router = express();
|
|
|
|
router.get("/page/blogs", auth, async function(req, res) {
|
|
res.json({
|
|
categories: await Categories.findAll(),
|
|
blogs: await getBlogs({myUserId: req.session.user.id})
|
|
});
|
|
});
|
|
|
|
router.get("/page/blogs/:cate", auth, async function(req, res) {
|
|
res.json({
|
|
categories: await Categories.findAll(),
|
|
blogs: await getBlogsWithCategory({categoryTitle: req.params.cate, myUserId: req.session.user.id}),
|
|
currentCategory: await getCategoryWithParams({categoryTitle: req.params.cate})
|
|
});
|
|
});
|
|
|
|
module.exports = router; |