i will get the Array of Answers
but how to get the Answered users info;
the flow is Get List of Posts, Post User Info, Post User Followers Count, Post Likes Count, Login User Liked The Post True or False, Answers, Answered User Info and Answered User Followers Count
exports.GetPostList = function(req, res) {
var SkipCoun = 0;
SkipCoun = parseInt(req.params.Limit) * 10;
QuestionsPostModel.QuestionsPostType.find({}, {} , {sort:{createdAt : -1}, skip: SkipCoun, limit: 10 }, function(err, result) {
if(err) {
res.status(500).send({status:"False", message: "Some error occurred while Find Following Users ."});
} else {
const GetUserData = (result) =>
Promise.all(
result.map(info => getPostInfo(info))
).then(
results => {
let [UserInfo, UserFollowers, PostRatingCount, UserRatedCount, AnswersCount, AswersArray ] =
results.reduce(([allOne, allTwo, allThree, allFour, allFive, allSix ], [one, two, three, four, five, six]) =>
[allOne.concat([one]), allTwo.concat([two]), allThree.concat([three]), allFour.concat([four]), allFive.concat([five]), allSix.concat([six])], [ [], [], [], [], [], [] ]);
res.send({ status: "True", UserInfo: UserInfo, UserFollowers: UserFollowers, PostRatingCount: PostRatingCount, UserRatedCount: UserRatedCount, AnswersCount:AnswersCount, AswersArray:AswersArray })
}
).catch(err => res.send({ status: "Fale",Error: err}) );
const getPostInfo = info =>
Promise.all([
UserModel.UserType.findOne({'_id': info.UserId }, usersProjection).exec(),
FollowModel.FollowUserType.count({'UserId': info.UserId}).exec(),
RatingModel.QuestionsRating.count({'PostId': info._id , 'ActiveStates':'Active' }).exec(),
RatingModel.QuestionsRating.count({'UserId': req.params.UserId, 'PostId': info._id, 'PostUserId': info.UserId, 'ActiveStates':'Active'}).exec(),
AnswerModel.QuestionsAnwer.count({'PostId': info._id , 'ActiveStates':'Active' }).exec(),
AnswerModel.QuestionsAnwer.find({ 'PostId':info._id }, 'AnswerText UserId Date' ).exec()
]);
GetUserData(result);
}
});
};
How to Get The Result