70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
const { Follow } = require("../../follows/models");
|
|
const { Gender, Education } = require("../models/user");
|
|
const { followButton } = require("../../follows/middlewares/process");
|
|
const { getFollowers, getFollowings } = require("../../follows/middlewares/query");
|
|
const { Op } = require("sequelize");
|
|
const { CustomSettings } = require("../../settings/models/Settings");
|
|
|
|
const User = require("../models/user").User;
|
|
|
|
exports.getUsers = async function(){
|
|
return await User.findAll();
|
|
};
|
|
|
|
exports.getUserWithId = async function({userId}) {
|
|
return await User.findOne({
|
|
where:{
|
|
id: userId
|
|
},
|
|
include: [Gender, Education, CustomSettings]
|
|
});
|
|
}
|
|
|
|
exports.getUserWithUsername = async function({username, myUserId=null}){
|
|
const result = await User.findOne({
|
|
where:{
|
|
username: username
|
|
},
|
|
include: [Gender, Education, {
|
|
model: Follow,
|
|
where: {
|
|
user: myUserId
|
|
},
|
|
include: {
|
|
model: User,
|
|
as: 'following',
|
|
where: {
|
|
username: username
|
|
}
|
|
},
|
|
required: false
|
|
}]
|
|
});
|
|
|
|
if(result){
|
|
result.dataValues.followers = (await getFollowers({userId: result.id, statu: true})).data;
|
|
result.dataValues.followings = (await getFollowings({userId: result.id, statu: true})).data;
|
|
|
|
if(result.follows.length > 0){
|
|
followButton({data: result.follows[0], myUserId: myUserId});
|
|
}else{
|
|
result.dataValues.button = new Object({
|
|
text: "Takip Et"
|
|
});
|
|
};
|
|
}
|
|
return result;
|
|
};
|
|
|
|
exports.getUsersDiscover = async function({userId}) {
|
|
return User.findAll({
|
|
include: {
|
|
model: Follow,
|
|
where: {
|
|
[Op.not]: {
|
|
user: userId
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}; |