You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varsort=query.sort;// -fieldName: means descending while fieldName without the minus mean ascending bith by fieldName. eg, '-fieldName1 fieldName2'
67
-
if(sort){
68
-
deletequery.sort;
69
-
}
70
-
varpopulate=query.populate;// Samples: 'name location' will populate name and location references. only supports this for now | 'name', 'firstname' will populate name referenece and only pick the firstname attribute
71
-
vartotal=Users.count(query);
72
-
varquestion=Users.find(query);
73
-
74
-
if(limit){
75
-
varourLimit=limit*1;
76
-
question=question.limit(limit);
77
-
}else{
78
-
limit=0;
79
-
}
80
-
if(sort){
81
-
question=question.sort(sort);
82
-
}
83
-
if(populate){
84
-
question=question.populate(populate);
85
-
}
86
-
87
-
if(projection){
88
-
q.all([ourProjection,total])
89
-
.spread(function(resp,total){
90
-
return[question.select(resp),total];
91
-
})
92
-
.spread(function(resp,total){
93
-
varourLastId=resp[resp.length-1]._id;
94
-
varextraData={};
95
-
extraData.limit=limit*1;
96
-
extraData.total=total;
97
-
extraData.lastId=ourLastId;
98
-
res.ok(resp,false,extraData);
35
+
varquery;
36
+
if(req.query.search){
37
+
query=req.query.query;
38
+
Users.search(query)
39
+
.then(function(resp){
40
+
res.ok(resp);
99
41
})
100
42
.catch(function(err){
101
43
next(err);
102
44
});
45
+
// ToDo: Test that search works
103
46
}else{
104
-
q.all([question,total])
105
-
.spread(function(resp,total){
106
-
varourLastId=resp[resp.length-1]._id;
107
-
varextraData={};
108
-
extraData.limit=limit*1;
109
-
extraData.total=total;
110
-
extraData.lastId=ourLastId;
111
-
res.ok(resp,false,extraData);
112
-
})
113
-
.catch(function(err){
114
-
next(err);
115
-
});
116
-
// ToDo: Test limiting
117
-
// ToDO: Test that response contains count of total record for the query
118
-
// ToDo: Test that the last document Id in the return array of documents is in the response
119
-
// ToDo: Test that sorting works
120
-
// ToDo: Test that projection works
121
-
// ToDo: Test that populating works
122
-
// ToDo: Test that date range works
47
+
query=req.query;
48
+
varprojection=query.projection.split(',');
49
+
varourProjection;
50
+
query.createdAt={};
51
+
if(projection){
52
+
ourProjection=this.buildProjection(projection);
53
+
deletequery.projection;
54
+
}
55
+
varlimit=query.limit;
56
+
if(limit){
57
+
deletequery.limit;
58
+
}
59
+
varto=query.to;
60
+
if(to){
61
+
deletequery.to;
62
+
}
63
+
varfrom=query.from;
64
+
if(from){
65
+
query.createdAt.$gt=from;
66
+
deletequery.from;
67
+
if(!to){
68
+
to=newDate().toISOString();
69
+
}
70
+
query.createdAt.$lt=to;
71
+
}
72
+
varlastId=query.lastId;
73
+
if(lastId){
74
+
query._id={};
75
+
query._id.$gt=lastId;
76
+
deletequery.lastId;
77
+
}
78
+
varsort=query.sort;// -fieldName: means descending while fieldName without the minus mean ascending bith by fieldName. eg, '-fieldName1 fieldName2'
79
+
if(sort){
80
+
deletequery.sort;
81
+
}
82
+
varpopulate=query.populate;// Samples: 'name location' will populate name and location references. only supports this for now | 'name', 'firstname' will populate name referenece and only pick the firstname attribute
83
+
vartotal=Users.count(query);
84
+
varquestion=Users.find(query);
85
+
86
+
if(limit){
87
+
varourLimit=limit*1;
88
+
question=question.limit(limit);
89
+
}else{
90
+
limit=0;
91
+
}
92
+
if(sort){
93
+
question=question.sort(sort);
94
+
}
95
+
if(populate){
96
+
question=question.populate(populate);
97
+
}
98
+
99
+
if(projection){
100
+
q.all([ourProjection,total])
101
+
.spread(function(resp,total){
102
+
return[question.select(resp),total];
103
+
})
104
+
.spread(function(resp,total){
105
+
varourLastId=resp[resp.length-1]._id;
106
+
varextraData={};
107
+
extraData.limit=limit*1;
108
+
extraData.total=total;
109
+
extraData.lastId=ourLastId;
110
+
res.ok(resp,false,extraData);
111
+
})
112
+
.catch(function(err){
113
+
next(err);
114
+
});
115
+
}else{
116
+
q.all([question,total])
117
+
.spread(function(resp,total){
118
+
varourLastId=resp[resp.length-1]._id;
119
+
varextraData={};
120
+
extraData.limit=limit*1;
121
+
extraData.total=total;
122
+
extraData.lastId=ourLastId;
123
+
res.ok(resp,false,extraData);
124
+
})
125
+
.catch(function(err){
126
+
next(err);
127
+
});
128
+
// ToDo: Test limiting
129
+
// ToDO: Test that response contains count of total record for the query
130
+
// ToDo: Test that the last document Id in the return array of documents is in the response
0 commit comments