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

@@ -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']]