Separate pins & listings
This commit is contained in:
@@ -78,7 +78,7 @@
|
||||
|
||||
router.get('/search/listings', function () {
|
||||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(req, res, next) {
|
||||
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, page, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, and, allRooms, or, size, allCategories, _or, cnt, all;
|
||||
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, page, pins, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, and, allRooms, or, size, allCategories, _or, cnt, all;
|
||||
|
||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
@@ -95,6 +95,7 @@
|
||||
category = req.query.category;
|
||||
sort = req.query.sort;
|
||||
page = req.query.page || 0;
|
||||
pins = req.query.pins || false;
|
||||
properties = db.collection('listings');
|
||||
query = {};
|
||||
|
||||
@@ -190,37 +191,42 @@
|
||||
});
|
||||
}
|
||||
|
||||
//query = Object.assign(query, {
|
||||
//"_id": 1
|
||||
//});
|
||||
|
||||
console.log('QUERY: ', query);
|
||||
_context.next = 24;
|
||||
_context.next = 25;
|
||||
return properties.find(query).count();
|
||||
|
||||
case 24:
|
||||
case 25:
|
||||
cnt = _context.sent;
|
||||
|
||||
|
||||
res.header('X-Total-Count', cnt);
|
||||
|
||||
//if (lastRecordId) {
|
||||
//query = Object.assign(query, {
|
||||
//"_id": {
|
||||
//"$gt": new ObjectID(lastRecordId)
|
||||
//}
|
||||
//});
|
||||
//}
|
||||
|
||||
_context.next = 28;
|
||||
return properties.find(query, {
|
||||
all = properties.find(query, {
|
||||
//"sort": [['field1','asc'], ['field2','desc']]
|
||||
"sort": [['price', 'asc']]
|
||||
}).skip(20 * page).limit(20).toArray();
|
||||
});
|
||||
|
||||
case 28:
|
||||
if (!(pins !== "true")) {
|
||||
_context.next = 34;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.next = 31;
|
||||
return all.skip(20 * page).limit(20).toArray();
|
||||
|
||||
case 31:
|
||||
all = _context.sent;
|
||||
_context.next = 37;
|
||||
break;
|
||||
|
||||
case 34:
|
||||
_context.next = 36;
|
||||
return all.toArray();
|
||||
|
||||
case 36:
|
||||
all = _context.sent;
|
||||
|
||||
case 37:
|
||||
|
||||
if (all.length > 0) {
|
||||
res.header('X-Last-Record-Id', [].concat(_toConsumableArray(all)).pop()._id);
|
||||
@@ -228,22 +234,22 @@
|
||||
|
||||
res.json(all);
|
||||
res.end();
|
||||
_context.next = 38;
|
||||
_context.next = 46;
|
||||
break;
|
||||
|
||||
case 34:
|
||||
_context.prev = 34;
|
||||
case 42:
|
||||
_context.prev = 42;
|
||||
_context.t0 = _context['catch'](0);
|
||||
|
||||
console.log('error:', _context.t0);
|
||||
next(_context.t0);
|
||||
|
||||
case 38:
|
||||
case 46:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined, [[0, 34]]);
|
||||
}, _callee, undefined, [[0, 42]]);
|
||||
}));
|
||||
|
||||
return function (_x, _x2, _x3) {
|
||||
|
||||
@@ -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