güncelleme
This commit is contained in:
parent
88839b0f4d
commit
c3d2ebd4a8
@ -71,6 +71,31 @@ router.get("/get/blogs/user/:username/:category", auth, async function (req, res
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/saved/user/:username", auth, async function (req, res) {
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
console.log(63);
|
||||
|
||||
res.json(await getBlogsWithUserId({
|
||||
userId: await getUserWithUsername({username: req.params.username}).then(get => get.id),
|
||||
myUserId: req.session.user.id,
|
||||
endDate: (req.query.endDate) ?? false,
|
||||
blogIds: blogIds
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/saved/user/:username/:category", auth, async function (req, res) {
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
|
||||
|
||||
res.json(await getBlogsWithUserId({
|
||||
userId: await getUserWithUsername({username: req.params.username}).then(get => get.id),
|
||||
category: req.params.category,
|
||||
myUserId: req.session.user.id,
|
||||
endDate: (req.query.endDate) ?? false,
|
||||
blogIds: blogIds
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/cate/all", async function(req, res) {
|
||||
res.json(await Categories.findAll());
|
||||
});
|
||||
|
||||
@ -3,8 +3,10 @@ const app = express();
|
||||
|
||||
// ROUTES
|
||||
const routePost = require("./routes/post");
|
||||
const routeGet = require("./routes/get");
|
||||
|
||||
// APPS
|
||||
app.use(routePost);
|
||||
app.use(routeGet);
|
||||
|
||||
module.exports = app;
|
||||
19
modules/comments/middlewares/get.js
Normal file
19
modules/comments/middlewares/get.js
Normal file
@ -0,0 +1,19 @@
|
||||
const { buildDatetime } = require("../../../middlewares/general/datatime");
|
||||
const { User } = require("../../users/models/user");
|
||||
const { Comments } = require("../models/Comments")
|
||||
|
||||
exports.getComments = async function({postId}){
|
||||
const result = await Comments.findAll({
|
||||
where: {
|
||||
blogId: postId
|
||||
},
|
||||
include: User
|
||||
});
|
||||
result.map(get => {
|
||||
get.datetime = new Object({
|
||||
createdAt: buildDatetime(get)
|
||||
});
|
||||
console.log(get, 582)
|
||||
});
|
||||
return result;
|
||||
};
|
||||
10
modules/comments/routes/get.js
Normal file
10
modules/comments/routes/get.js
Normal file
@ -0,0 +1,10 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { getComments } = require("../middlewares/get");
|
||||
const router = express();
|
||||
|
||||
router.get("/get/comments/:postid", auth, async function(req, res){
|
||||
res.json(await getComments({postId: req.params.postid}));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@ -4,11 +4,14 @@ const { followButton } = require("../../follows/middlewares/process");
|
||||
const { getFollowers, getFollowings } = require("../../follows/middlewares/query");
|
||||
const { Op } = require("sequelize");
|
||||
const { CustomSettings } = require("../../settings/models/Settings");
|
||||
const Blogs = require("../../blogs/models/Blogs");
|
||||
|
||||
const User = require("../models/user").User;
|
||||
|
||||
exports.getUsers = async function(){
|
||||
return await User.findAll();
|
||||
return await User.findAll({
|
||||
include: [Blogs, CustomSettings]
|
||||
});
|
||||
};
|
||||
|
||||
exports.getUserWithId = async function({userId}) {
|
||||
@ -57,13 +60,18 @@ exports.getUserWithUsername = async function({username, myUserId=null}){
|
||||
};
|
||||
|
||||
exports.getUsersDiscover = async function({userId}) {
|
||||
return User.findAll({
|
||||
include: {
|
||||
model: Follow,
|
||||
const followings = await Follow.findAll({
|
||||
where:{
|
||||
[Op.not]: {
|
||||
user: userId
|
||||
}
|
||||
});
|
||||
|
||||
const followingsIds = followings.map(res => res.target_user);
|
||||
console.log(followingsIds)
|
||||
return User.findAll({
|
||||
where: {
|
||||
[Op.not]: {
|
||||
id: [...followingsIds, userId]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user