Changed to avoid falsy values and not defined realestate parametrs.
This commit is contained in:
@@ -175,8 +175,8 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
[Op.and]: geoSearchQueryPart
|
||||
};
|
||||
|
||||
//Every other attribute is checked separately and included in query only if it is defined
|
||||
if (gardenSizeMax && gardenSizeMin) {
|
||||
//Every other attribute is checked separately and included in query only if it is defined/not null
|
||||
if (gardenSizeMax!=null && gardenSizeMin!=null) {
|
||||
query.gardenSize = {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
@@ -192,7 +192,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (numberOfRoomsMin && numberOfRoomsMax) {
|
||||
if (numberOfRoomsMin!=null && numberOfRoomsMax!=null) {
|
||||
query.numberOfRooms = {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
@@ -208,7 +208,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (numberOfFloorsMin && numberOfFloorsMax) {
|
||||
if (numberOfFloorsMin!=null && numberOfFloorsMax!=null) {
|
||||
query.numberOfFloors = {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
@@ -224,7 +224,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (floorMin && floorMax) {
|
||||
if (floorMin!=null && floorMax!=null) {
|
||||
query.floor = {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
@@ -240,7 +240,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (balcony) {
|
||||
if (balcony!=null) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
};
|
||||
@@ -252,7 +252,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (newBuilding) {
|
||||
if (newBuilding!=null) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
};
|
||||
@@ -264,7 +264,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (elevator) {
|
||||
if (elevator!=null) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
};
|
||||
|
||||
@@ -61,10 +61,10 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
//Needed to decide on including incomplete RealEstates data
|
||||
let checkForIncompleteWanted = false;
|
||||
|
||||
//Attributes are checked separately and included in query only if defined
|
||||
//Price and area should be defined for every property
|
||||
//Attributes are checked separately and included in query only if defined - not null
|
||||
|
||||
if (price) {
|
||||
//Price and area should be defined for every property
|
||||
if (price != null) {
|
||||
query.priceMin = {
|
||||
[Op.lte]: price
|
||||
};
|
||||
@@ -73,7 +73,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
};
|
||||
}
|
||||
|
||||
if (area) {
|
||||
if (area != null) {
|
||||
query.sizeMin = {
|
||||
[Op.lte]: area
|
||||
};
|
||||
@@ -84,51 +84,61 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
//Other attributes can be defined or not depending on RealEstate type
|
||||
if (gardenSize) {
|
||||
query.gardenSizeMin = {
|
||||
[Op.lte]: gardenSize
|
||||
};
|
||||
query.gardenSizeMax = {
|
||||
[Op.gte]: gardenSize
|
||||
};
|
||||
} else if (realEstateTypeObject.hasGardenSize) {
|
||||
checkForIncompleteWanted = true;
|
||||
//we check what to include in query based on real estate type object
|
||||
if (realEstateTypeObject.hasGardenSize) {
|
||||
if (gardenSize != null) {
|
||||
query.gardenSizeMin = {
|
||||
[Op.lte]: gardenSize
|
||||
};
|
||||
query.gardenSizeMax = {
|
||||
[Op.gte]: gardenSize
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfRooms) {
|
||||
query.numberOfRoomsMin = {
|
||||
[Op.lte]: numberOfRooms
|
||||
};
|
||||
query.numberOfRoomsMax = {
|
||||
[Op.gte]: numberOfRooms
|
||||
};
|
||||
} else if (realEstateTypeObject.hasNumberOfRoom) {
|
||||
checkForIncompleteWanted = true;
|
||||
if (realEstateTypeObject.hasNumberOfRoom) {
|
||||
if (numberOfRooms != null) {
|
||||
query.numberOfRoomsMin = {
|
||||
[Op.lte]: numberOfRooms
|
||||
};
|
||||
query.numberOfRoomsMax = {
|
||||
[Op.gte]: numberOfRooms
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfFloors) {
|
||||
query.numberOfFloorsMin = {
|
||||
[Op.lte]: numberOfFloors
|
||||
};
|
||||
query.numberOfFloorsMax = {
|
||||
[Op.gte]: numberOfFloors
|
||||
};
|
||||
} else if (realEstateTypeObject.hasNumberOfFloors) {
|
||||
checkForIncompleteWanted = true;
|
||||
if (realEstateTypeObject.hasNumberOfFloors) {
|
||||
if (numberOfFloors != null) {
|
||||
query.numberOfFloorsMin = {
|
||||
[Op.lte]: numberOfFloors
|
||||
};
|
||||
query.numberOfFloorsMax = {
|
||||
[Op.gte]: numberOfFloors
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (floor) {
|
||||
query.floorMin = {
|
||||
[Op.lte]: floor
|
||||
};
|
||||
query.floorMax = {
|
||||
[Op.gte]: floor
|
||||
};
|
||||
} else if (realEstateTypeObject.hasFloorProp) {
|
||||
checkForIncompleteWanted = true;
|
||||
if (realEstateTypeObject.hasFloorProp) {
|
||||
if (floor != null) {
|
||||
query.floorMin = {
|
||||
[Op.lte]: floor
|
||||
};
|
||||
query.floorMax = {
|
||||
[Op.gte]: floor
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (accessRoadType) {
|
||||
//AccessRoadType is defined - should exits for each ad and estate type
|
||||
if (accessRoadType != null) {
|
||||
query.accessRoadType = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: "ANY",
|
||||
@@ -139,28 +149,34 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
|
||||
if (balcony) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
};
|
||||
} else if (realEstateTypeObject.hasBalconyProp) {
|
||||
checkForIncompleteWanted = true;
|
||||
if (realEstateTypeObject.hasBalconyProp) {
|
||||
if (balcony != null) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (newBuilding) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
};
|
||||
} else if (realEstateTypeObject.hasNewBuildingProp) {
|
||||
checkForIncompleteWanted = true;
|
||||
if (realEstateTypeObject.hasNewBuildingProp) {
|
||||
if (newBuilding != null) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (elevator) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
};
|
||||
} else if (realEstateTypeObject.hasElevatorProp) {
|
||||
checkForIncompleteWanted = true;
|
||||
if (realEstateTypeObject.hasElevatorProp) {
|
||||
if (elevator != null) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
};
|
||||
} else {
|
||||
checkForIncompleteWanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
//If one of the attributes that exists for property type is null
|
||||
|
||||
Reference in New Issue
Block a user