kişiler, bloglar ve profil düzenlendi. Profilde yaşanan render sorunu çözüme kavuşturuldu. Servisler componenti eklendi.
This commit is contained in:
parent
007bb96c04
commit
a88dc25ef4
@ -1,19 +1,44 @@
|
||||
const User = require("../../users/models/user");
|
||||
const Blogs = require("../models/Blogs")
|
||||
const Blogs = require("../models/Blogs");
|
||||
const Categories = require("../models/Categories");
|
||||
|
||||
exports.getBlogs = async function(){
|
||||
return await Blogs.findAll({
|
||||
include: User
|
||||
include: [User, Categories]
|
||||
});
|
||||
};
|
||||
|
||||
exports.getBlogsWithUsername = async function({username}){
|
||||
return await Blogs.findAll({
|
||||
include:{
|
||||
include:[Categories, {
|
||||
model: User,
|
||||
where: {
|
||||
username: username
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
exports.getBlogsWithCategory = async function({categoryId, categoryTitle}){
|
||||
return await Blogs.findAll({
|
||||
include: [User, Categories, {
|
||||
model: Categories,
|
||||
where: [(categoryId) && {
|
||||
id: categoryId
|
||||
}, (categoryTitle) && {
|
||||
title: categoryTitle
|
||||
}]
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// CATE
|
||||
exports.getCategoryWithParams = async function({categoryId, categoryTitle}){
|
||||
return await Categories.findOne({
|
||||
where:[
|
||||
(categoryId) ? {id: categoryId} : {},
|
||||
(categoryTitle) ? {title: categoryTitle} : {}
|
||||
]
|
||||
});
|
||||
};
|
||||
@ -1,12 +1,16 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { getBlogs, getBlogsWithUsername } = require("../middlewares/query");
|
||||
const { getBlogs, getBlogsWithUsername, getBlogsWithCategory } = require("../middlewares/query");
|
||||
const router = express();
|
||||
|
||||
router.get("/get/blogs/all", auth, async function (req, res) {
|
||||
res.json(await getBlogs());
|
||||
});
|
||||
|
||||
router.get("/get/blogs/:cate", auth, async function(req, res) {
|
||||
res.json(await getBlogsWithCategory({categoryId: req.params.cate}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/user/:username", auth, async function (req, res) {
|
||||
res.json(await getBlogsWithUsername({
|
||||
username: req.params.username
|
||||
|
||||
@ -1,11 +1,21 @@
|
||||
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()
|
||||
categories: await Categories.findAll(),
|
||||
blogs: await getBlogs()
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/page/blogs/:cate", auth, async function(req, res) {
|
||||
res.json({
|
||||
categories: await Categories.findAll(),
|
||||
blogs: await getBlogsWithCategory({categoryTitle: req.params.cate}),
|
||||
currentCategory: await getCategoryWithParams({categoryTitle: req.params.cate})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -7,6 +7,12 @@ router.get("/get/peoples", auth, async (req, res) => {
|
||||
res.json(await getUsers({myUserId: req.session.user.id}));
|
||||
});
|
||||
|
||||
router.get("/get/user/my", auth, async (req, res) => {
|
||||
res.json({
|
||||
username: req.session.user.username
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/get/user/:username", async (req, res) => {
|
||||
res.json(await getUserWithUsername({username: req.params.username}))
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user