110 lines
2.7 KiB
JavaScript
110 lines
2.7 KiB
JavaScript
const Blogs = require("../../blogs/models/Blogs");
|
|
const { CustomSettings } = require("../../settings/models/Settings");
|
|
const { User } = require("../../users/models/user");
|
|
const { Follow } = require("../models");
|
|
const { followButton } = require("./process");
|
|
|
|
exports.searchFollow = async function({user, targetUser}){
|
|
if(user !== targetUser){
|
|
const query = await Follow.findOne({
|
|
where:{
|
|
user: user,
|
|
target_user: targetUser
|
|
},
|
|
include: [
|
|
{ model: User, as: 'follower' },
|
|
{ model: User, as: 'following' }
|
|
]
|
|
});
|
|
return {
|
|
Status: "Success",
|
|
isMy: false,
|
|
isNull: (query) ? false : true,
|
|
data: query
|
|
}
|
|
}else if(user === targetUser){
|
|
return {
|
|
Status: "Success",
|
|
isMy: true,
|
|
isNull: true
|
|
};
|
|
}else{
|
|
return {
|
|
Status: "Success",
|
|
isNull: true
|
|
}
|
|
};
|
|
};
|
|
|
|
exports.getFollowers = async function({userId, statu = true, myUserId = null}){
|
|
const result = await Follow.findAll({
|
|
where:{
|
|
target_user: userId,
|
|
statu: statu
|
|
},
|
|
include: {
|
|
model: User,
|
|
include: [Blogs, CustomSettings],
|
|
as: "follower"
|
|
}
|
|
});
|
|
|
|
const isLen = result.length > 0;
|
|
|
|
if(isLen === true && myUserId !== null){
|
|
for (let index = 0; index < result.length; index++) {
|
|
const element = result[index];
|
|
await followButton({
|
|
data: element,
|
|
myUserId: myUserId
|
|
});
|
|
};
|
|
};
|
|
|
|
return {
|
|
Status: "Success",
|
|
isNull: !isLen,
|
|
data: result
|
|
};
|
|
};
|
|
|
|
exports.getFollowings = async function({userId, statu = true, myUserId = null}){
|
|
const result = await Follow.findAll({
|
|
where:{
|
|
user: userId,
|
|
statu: statu
|
|
},
|
|
include: {
|
|
model: User,
|
|
include: [Blogs, CustomSettings],
|
|
as: "following"
|
|
}
|
|
});
|
|
|
|
const isLen = result.length > 0;
|
|
|
|
if(isLen === true && myUserId !== null){
|
|
for (let index = 0; index < result.length; index++) {
|
|
const element = result[index];
|
|
await followButton({
|
|
data: element,
|
|
myUserId: myUserId
|
|
})
|
|
};
|
|
}
|
|
|
|
return {
|
|
Status: "Success",
|
|
isNull: !isLen,
|
|
data: result
|
|
};
|
|
};
|
|
|
|
exports.getFollowingsForIds = async function({userId}) {
|
|
const result = await Follow.findAll({
|
|
where: {
|
|
user: userId
|
|
}
|
|
});
|
|
return result.map(res => res.target_user);
|
|
}; |