async function profileResponse(user, me, followStatus, TradingEqFollow, Article, Portfolio, PortfolioTradingEq, PortfolioFollow, User) {
  let followings = await findUserFollows({ FollowingId: user._id, status: true })
  let followers = await findUserFollows({ FollowedId: user._id, status: true })
  let followRequests = await findUserFollows({ FollowedId: user._id, status: false})
  let followingTradings = await TradingEqFollow.find({ UserId : user._id })
  let followingPortfoliosTemp = await PortfolioFollow.find({ UserId : user._id })
  let articles = await Article.find().where('userId').equals(user._id)
  let portfoliosBefore = null
  let followingPortfolios = []
  let portfolios = []
  if(me){
    portfoliosBefore = await Portfolio.find().where('userId').equals(user._id)   
  }
  else{
    portfoliosBefore = await Portfolio.find({userId: user._id, isPrivate: false})
  }

  for (const portfolio of portfoliosBefore) {
    let tradingEqsObj = await PortfolioTradingEq.find({ PortfolioId : portfolio._id})
    let tradingEqs = []
    for (const tradingEq of tradingEqsObj) {
      tradingEqs.push(tradingEq['TradingEq']);
    }
    obj = {
      ...portfolio["_doc"],
      tradingEqs: tradingEqs
    }
    portfolios.push(obj)
  }

  for(const p of followingPortfoliosTemp){
    let temp = await Portfolio.find({ _id : p['PortfolioId']})
    let user = await User.find({_id : temp[0]['userId']})
    obj = {
      ...temp[0]["_doc"],
      userId: user[0]['_id'],
      username: user[0]['name'],
      surname: user[0]['surname'],
      PortfolioId: p['PortfolioId']
    }
    followingPortfolios.push(obj)
  }

  if(me){ // if profile is mine
    obj = {
      user,
      following: followings.length,
      followings,
      follower: followers.length,
      followers,
      followRequest: followRequests.length,
      followRequests,
      followingTradings,
      articles,
      portfolios,
      followingPortfolios
    }
    return obj;
  } else { // if profile is others
      if (user.isPublic || followStatus == 'TRUE') { // if profile is public or i am following
        tempUser = { _id : user._id, 
          isTrader : user.isTrader, 
          isPublic : user.isPublic, 
          name : user.name, 
          surname : user.surname, 
          email : user.email, 
          location: user.location,
          predictionRate: user.predictionRate,
          followingPortfolios
        }

        obj = {
          user : tempUser,
          following: followings.length,
          followings,
          follower: followers.length,
          followers,
          followStatus,
          followingTradings,
          articles,
          portfolios,
          followingPortfolios
      }
      return obj;
      } else { // if profile is private and i am not following right now.
        tempUser = { _id : user._id, 
          isPublic : user.isPublic, 
          name : user.name, 
          surname : user.surname
        }

        obj = {
          user: tempUser,
          following: followings.length,
          follower: followers.length,
          articles,
          followStatus
        }
        return obj
    }
  }
}
/*
  Get method for profile page.
  Get user id from parameter and responses accordingly.
*/
Get method for profile page.
Get user id from parameter and responses accordingly.
Get method for profile page . Get user id from parameter and responses accordingly .
async function profileResponse(user, me, followStatus, TradingEqFollow, Article, Portfolio, PortfolioTradingEq, PortfolioFollow, User) {
  let followings = await findUserFollows({ FollowingId: user._id, status: true })
  let followers = await findUserFollows({ FollowedId: user._id, status: true })
  let followRequests = await findUserFollows({ FollowedId: user._id, status: false})
  let followingTradings = await TradingEqFollow.find({ UserId : user._id })
  let followingPortfoliosTemp = await PortfolioFollow.find({ UserId : user._id })
  let articles = await Article.find().where('userId').equals(user._id)
  let portfoliosBefore = null
  let followingPortfolios = []
  let portfolios = []
  if(me){
    portfoliosBefore = await Portfolio.find().where('userId').equals(user._id)   
  }
  else{
    portfoliosBefore = await Portfolio.find({userId: user._id, isPrivate: false})
  }
  for (const portfolio of portfoliosBefore) {
    let tradingEqsObj = await PortfolioTradingEq.find({ PortfolioId : portfolio._id})
    let tradingEqs = []
    for (const tradingEq of tradingEqsObj) {
      tradingEqs.push(tradingEq['TradingEq']);
    }
    obj = {
      ...portfolio["_doc"],
      tradingEqs: tradingEqs
    }
    portfolios.push(obj)
  }
  for(const p of followingPortfoliosTemp){
    let temp = await Portfolio.find({ _id : p['PortfolioId']})
    let user = await User.find({_id : temp[0]['userId']})
    obj = {
      ...temp[0]["_doc"],
      userId: user[0]['_id'],
      username: user[0]['name'],
      surname: user[0]['surname'],
      PortfolioId: p['PortfolioId']
    }
    followingPortfolios.push(obj)
  }
  if(me){ 
    obj = {
      user,
      following: followings.length,
      followings,
      follower: followers.length,
      followers,
      followRequest: followRequests.length,
      followRequests,
      followingTradings,
      articles,
      portfolios,
      followingPortfolios
    }
    return obj;
  } else { 
      if (user.isPublic || followStatus == 'TRUE') { 
        tempUser = { _id : user._id, 
          isTrader : user.isTrader, 
          isPublic : user.isPublic, 
          name : user.name, 
          surname : user.surname, 
          email : user.email, 
          location: user.location,
          predictionRate: user.predictionRate,
          followingPortfolios
        }
        obj = {
          user : tempUser,
          following: followings.length,
          followings,
          follower: followers.length,
          followers,
          followStatus,
          followingTradings,
          articles,
          portfolios,
          followingPortfolios
      }
      return obj;
      } else { 
        tempUser = { _id : user._id, 
          isPublic : user.isPublic, 
          name : user.name, 
          surname : user.surname
        }
        obj = {
          user: tempUser,
          following: followings.length,
          follower: followers.length,
          articles,
          followStatus
        }
        return obj
    }
  }
}
async function profileResponse ( user , me , followStatus , TradingEqFollow , Article , Portfolio , PortfolioTradingEq , PortfolioFollow , User ) { let followings = await findUserFollows ( { FollowingId : user . _id , status : true } ) let followers = await findUserFollows ( { FollowedId : user . _id , status : true } ) let followRequests = await findUserFollows ( { FollowedId : user . _id , status : false } ) let followingTradings = await TradingEqFollow . find ( { UserId : user . _id } ) let followingPortfoliosTemp = await PortfolioFollow . find ( { UserId : user . _id } ) let articles = await Article . find ( ) . where ( 'userId' ) . equals ( user . _id ) let portfoliosBefore = null let followingPortfolios = [ ] let portfolios = [ ] if ( me ) { portfoliosBefore = await Portfolio . find ( ) . where ( 'userId' ) . equals ( user . _id ) } else { portfoliosBefore = await Portfolio . find ( { userId : user . _id , isPrivate : false } ) } for ( const portfolio of portfoliosBefore ) { let tradingEqsObj = await PortfolioTradingEq . find ( { PortfolioId : portfolio . _id } ) let tradingEqs = [ ] for ( const tradingEq of tradingEqsObj ) { tradingEqs . push ( tradingEq [ 'TradingEq' ] ) ; } obj = { ... portfolio [ "_doc" ] , tradingEqs : tradingEqs } portfolios . push ( obj ) } for ( const p of followingPortfoliosTemp ) { let temp = await Portfolio . find ( { _id : p [ 'PortfolioId' ] } ) let user = await User . find ( { _id : temp [ 0 ] [ 'userId' ] } ) obj = { ... temp [ 0 ] [ "_doc" ] , userId : user [ 0 ] [ '_id' ] , username : user [ 0 ] [ 'name' ] , surname : user [ 0 ] [ 'surname' ] , PortfolioId : p [ 'PortfolioId' ] } followingPortfolios . push ( obj ) } if ( me ) { obj = { user , following : followings . length , followings , follower : followers . length , followers , followRequest : followRequests . length , followRequests , followingTradings , articles , portfolios , followingPortfolios } return obj ; } else { if ( user . isPublic || followStatus == 'TRUE' ) { tempUser = { _id : user . _id , isTrader : user . isTrader , isPublic : user . isPublic , name : user . name , surname : user . surname , email : user . email , location : user . location , predictionRate : user . predictionRate , followingPortfolios } obj = { user : tempUser , following : followings . length , followings , follower : followers . length , followers , followStatus , followingTradings , articles , portfolios , followingPortfolios } return obj ; } else { tempUser = { _id : user . _id , isPublic : user . isPublic , name : user . name , surname : user . surname } obj = { user : tempUser , following : followings . length , follower : followers . length , articles , followStatus } return obj } } }
Get method for profile page.
Get method for profile page .
// if profile is mine // if profile is others // if profile is public or i am following // if profile is private and i am not following right now.