@@ -56,7 +56,6 @@ exports.getFeed = async(req, res) => {
5656 } ) ;
5757
5858 if ( ! currUser
59- // || !currUser.personalityType
6059 ) {
6160 return res
6261 . json ( {
@@ -65,8 +64,6 @@ exports.getFeed = async(req, res) => {
6564 } ) ;
6665 }
6766
68- // const currUserScoreFactors = cumulateMatchingFactors(currUser);
69-
7067 let userProfiles = await UserProfile . find ( {
7168 ...newFilters ,
7269 email : {
@@ -83,12 +80,6 @@ exports.getFeed = async(req, res) => {
8380 const lessPreferredGenderUser = [ ] ;
8481
8582 userProfiles . forEach ( otherUser => {
86- // const otherUserScoreFactors = cumulateMatchingFactors(otherUser);
87- // const scoredProfile = {
88- // score : calculateMatchingScore(currUserScoreFactors , otherUserScoreFactors) ,
89- // ...(otherUser.toObject())
90- // };
91-
9283 if (
9384 (
9485 currUser . gender !== otherUser . gender
@@ -100,11 +91,34 @@ exports.getFeed = async(req, res) => {
10091 ) {
10192 morePreferredGenderUser . push ( otherUser ) ;
10293 } else {
103- morePreferredGenderUser . push ( otherUser ) ;
94+ lessPreferredGenderUser . push ( otherUser ) ;
10495 }
10596 } ) ;
97+
98+ shuffleProfiles ( morePreferredGenderUser ) ;
99+ shuffleProfiles ( lessPreferredGenderUser ) ;
106100
107- let paginatedUsers = pickUsers ( morePreferredGenderUser , lessPreferredGenderUser ) ;
101+ const pageNumber = ( parseInt ( req . params . pageNumber , 10 ) || 0 ) % ( morePreferredGenderUser . length + lessPreferredGenderUser . length ) ;
102+ const pageSize = 10 ;
103+ const startIndex = pageNumber * pageSize ;
104+ const endIndex = startIndex + pageSize ;
105+
106+ let paginatedUsers = [ ] ;
107+
108+ const moreLength = morePreferredGenderUser . length ;
109+
110+ if ( startIndex < moreLength && endIndex <= moreLength ) {
111+ paginatedUsers = morePreferredGenderUser . slice ( startIndex , endIndex ) ;
112+ } else if ( startIndex < moreLength && endIndex > moreLength ) {
113+ const fromMore = morePreferredGenderUser . slice ( startIndex , moreLength ) ;
114+ const remaining = endIndex - moreLength ;
115+ const fromLess = lessPreferredGenderUser . slice ( 0 , remaining ) ;
116+ paginatedUsers = [ ...fromMore , ...fromLess ] ;
117+ } else {
118+ const newStart = startIndex - moreLength ;
119+ const newEnd = endIndex - moreLength ;
120+ paginatedUsers = lessPreferredGenderUser . slice ( newStart , newEnd ) ;
121+ }
108122
109123 shuffleProfiles ( paginatedUsers ) ;
110124
0 commit comments