私のアプリには、ユーザーが投稿したストーリーのリストがあります。ユーザーはストーリーをプライベートとしてマークして、自分だけがこれらのストーリーを見ることができるようにすることができます。クエリを作成しているユーザーのすべてのパブリック ストーリーとプライベート ストーリーのリストを取得する必要があり、ページネーションを使用できるように並べ替える必要があります。これまでのところ、私はこのようなものを持っています。
story.index = function(req, res, next) {
return Story.find({isPrivate: false})
.sort('-date_modified')
.exec(function(err, stories){
if(err){
return next(err);
}
/* If the user is authenticated, get his private stories */
if(req.isAuthenticated()){
Story.find({ _creator: req.user._id })
.sort('-date_modified')
.exec(function(err, privateStories){
/* Create a list with all stories */
var all = stories.concat(privateStories);
/* If have something in the list, return it */
if(all.length > 0){
return res.send(all);
}
/* Return a 404 otherwise */
else{
return res.send(404, {message: "No stories found"});
}
});
}
/* If the user is not authenticated, return the public stories */
else if(stories.length > 0){
return res.send(stories);
}
/* Or a 404 */
else{
return res.send(404, {message: "No stories found"});
}
});
};
しかし、これは明らかにプライベートストーリーを順番に追加していません。どうすればこの結果を得ることができますか?
ありがとう。