Make price filtering work
This commit is contained in:
@@ -48,52 +48,57 @@ router.get('/search', async (req, res, next) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (minPrice) {
|
||||
if (minPrice || maxPrice) {
|
||||
const price = {}
|
||||
if (minPrice) {
|
||||
price["$gte"] = parseFloat(minPrice);
|
||||
}
|
||||
|
||||
if (maxPrice) {
|
||||
price["$lte"] = parseFloat(maxPrice);
|
||||
}
|
||||
|
||||
query = Object.assign(query, {
|
||||
price: {
|
||||
"$gte": parseFloat(minPrice),
|
||||
"$ne": -1
|
||||
}
|
||||
price
|
||||
});
|
||||
}
|
||||
|
||||
if (maxPrice) {
|
||||
query = Object.assign(query, {
|
||||
price: {
|
||||
"$lte": parseFloat(maxPrice),
|
||||
"$ne": -1
|
||||
if (rooms) {
|
||||
const allRooms = rooms.split(',');
|
||||
const or = allRooms.map(val => {
|
||||
if (val === '4+') {
|
||||
return {
|
||||
rooms: {
|
||||
"$gte": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
rooms: parseFloat(val)
|
||||
};
|
||||
});
|
||||
|
||||
query = Object.assign(query, {
|
||||
"$or": or
|
||||
});
|
||||
}
|
||||
|
||||
if (rooms === "4+") {
|
||||
if (minSize || maxSize) {
|
||||
const size = {}
|
||||
if (minSize) {
|
||||
size["$gte"] = parseFloat(minSize);
|
||||
}
|
||||
|
||||
if (maxSize) {
|
||||
size["$lte"] = parseFloat(maxSize);
|
||||
}
|
||||
|
||||
query = Object.assign(query, {
|
||||
rooms: {
|
||||
"$gte": 4
|
||||
}
|
||||
})
|
||||
} else if (rooms) {
|
||||
query = Object.assign(query, {
|
||||
rooms: parseFloat(rooms)
|
||||
});
|
||||
}
|
||||
|
||||
if (minSize) {
|
||||
query = Object.assign(query, {
|
||||
size: {
|
||||
"$gte": parseFloat(minSize)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (maxSize) {
|
||||
query = Object.assign(query, {
|
||||
size: {
|
||||
"$lte": parseFloat(maxSize)
|
||||
}
|
||||
size
|
||||
});
|
||||
}
|
||||
|
||||
console.log('QUERY: ', query);
|
||||
const all = await properties.find(query).toArray();
|
||||
|
||||
res.json(all);
|
||||
|
||||
Reference in New Issue
Block a user