Separate pins & listings
This commit is contained in:
@@ -26,6 +26,7 @@ router.get('/search/listings', async (req, res, next) => {
|
||||
const category = req.query.category;
|
||||
const sort = req.query.sort;
|
||||
const page = req.query.page || 0;
|
||||
const pins = req.query.pins || false;
|
||||
|
||||
const properties = db.collection('listings');
|
||||
let query = {};
|
||||
@@ -115,27 +116,21 @@ router.get('/search/listings', async (req, res, next) => {
|
||||
});
|
||||
}
|
||||
|
||||
//query = Object.assign(query, {
|
||||
//"_id": 1
|
||||
//});
|
||||
|
||||
console.log('QUERY: ', query);
|
||||
const cnt = await properties.find(query).count();
|
||||
|
||||
res.header('X-Total-Count', cnt);
|
||||
|
||||
//if (lastRecordId) {
|
||||
//query = Object.assign(query, {
|
||||
//"_id": {
|
||||
//"$gt": new ObjectID(lastRecordId)
|
||||
//}
|
||||
//});
|
||||
//}
|
||||
|
||||
const all = await properties.find(query, {
|
||||
let all = properties.find(query, {
|
||||
//"sort": [['field1','asc'], ['field2','desc']]
|
||||
"sort": [['price','asc']]
|
||||
}).skip(20 * page).limit(20).toArray();
|
||||
});
|
||||
|
||||
if (pins !== "true") {
|
||||
all = await all.skip(20 * page).limit(20).toArray();
|
||||
} else {
|
||||
all = await all.toArray();
|
||||
}
|
||||
|
||||
if (all.length > 0) {
|
||||
res.header('X-Last-Record-Id', [...all].pop()._id);
|
||||
|
||||
Reference in New Issue
Block a user