Queries for db search changed. Needs testing.

This commit is contained in:
Naida Vatric
2019-12-14 01:10:48 +01:00
parent e83712fb33
commit 5a2fdb7291
2 changed files with 137 additions and 97 deletions

View File

@@ -26,7 +26,6 @@ const findSearchRequestsForRealEstate = async realEstate => {
realEstateType,
locationLat,
locationLong,
//
accessRoadType,
balcony,
newBuilding,
@@ -51,19 +50,15 @@ const findSearchRequestsForRealEstate = async realEstate => {
const geoSearchQueryPart = sequelize.where(contains, true);
//WIP This wont work, need to separate queries by adType and realEstateType
//because for example flat does not have gardenSize and that can't be in query
//General query contains only attributes that are defined for every realestate - not null
const query = {
adType,
realEstateType,
subscribed: true,
//
balcony,
newBuilding,
elevator,
[Op.and]: geoSearchQueryPart
};
//Every other attribute is checked separately and included in query only if it is defined
if (price) {
query.priceMin = {
[Op.lte]: price
@@ -81,7 +76,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.gte]: area
};
}
//
if (gardenSize) {
query.gardenSizeMin = {
[Op.lte]: gardenSize
@@ -90,6 +85,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.gte]: gardenSize
};
}
if (numberOfRooms) {
query.numberOfRoomsMin = {
[Op.lte]: numberOfRooms
@@ -98,6 +94,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.gte]: numberOfRooms
};
}
if (numberOfFloors) {
query.numberOfFloorsMin = {
[Op.lte]: numberOfFloors
@@ -106,6 +103,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.gte]: numberOfFloors
};
}
if (floor) {
query.floorMin = {
[Op.lte]: floor
@@ -114,6 +112,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.gte]: floor
};
}
if (accessRoadType) {
query.accessRoadType = {
[Op.or]: {
@@ -122,6 +121,25 @@ const findSearchRequestsForRealEstate = async realEstate => {
}
}
}
if (balcony) {
query.balcony = {
[Op.eq]: balcony
}
}
if (newBuilding) {
query.newBuilding = {
[Op.eq]: newBuilding
}
}
if (elevator) {
query.elevator = {
[Op.eq]: elevator
}
}
return await db.SearchRequest.findAll({ where: query });
};