Filters done

This commit is contained in:
Edin Dazdarevic
2017-04-05 02:02:43 +02:00
parent d2ee02b6df
commit 15dc596f3d
10 changed files with 150 additions and 30 deletions

View File

@@ -74,7 +74,7 @@
router.get('/search', function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(req, res, next) {
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, allRooms, or, size, all;
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, allRooms, or, size, allCategories, _or, all;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
@@ -88,6 +88,8 @@
maxSize = req.query.maxSize;
rooms = req.query.rooms;
adType = req.query.adType;
category = req.query.category;
sort = req.query.sort;
properties = db.collection('listings');
query = {};
@@ -165,35 +167,49 @@
});
}
if (category) {
allCategories = category.split(',');
_or = allCategories.map(function (val) {
return {
category: parseInt(val)
};
});
query = Object.assign(query, {
"$or": _or
});
}
console.log('QUERY: ', query);
_context.next = 18;
_context.next = 21;
return properties.find(query, {
//"sort": [['field1','asc'], ['field2','desc']]
"sort": [['price', 'asc']]
}).toArray();
case 18:
case 21:
all = _context.sent;
res.json(all);
res.end();
_context.next = 27;
_context.next = 30;
break;
case 23:
_context.prev = 23;
case 26:
_context.prev = 26;
_context.t0 = _context['catch'](0);
console.log('error:', _context.t0);
next(_context.t0);
case 27:
case 30:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[0, 23]]);
}, _callee, undefined, [[0, 26]]);
}));
return function (_x, _x2, _x3) {

View File

@@ -21,6 +21,8 @@ router.get('/search', async (req, res, next) => {
const maxSize = req.query.maxSize;
const rooms = req.query.rooms;
const adType = req.query.adType;
const category = req.query.category;
const sort = req.query.sort;
const properties = db.collection('listings');
let query = {};
@@ -93,6 +95,19 @@ router.get('/search', async (req, res, next) => {
});
}
if (category) {
const allCategories = category.split(',');
const or = allCategories.map(val => {
return {
category: parseInt(val)
};
});
query = Object.assign(query, {
"$or": or
});
}
console.log('QUERY: ', query);
const all = await properties.find(query, {
//"sort": [['field1','asc'], ['field2','desc']]