Changed to avoid falsy values and not defined realestate parametrs.

This commit is contained in:
Naida Vatric
2019-12-21 02:20:26 +01:00
parent bee390aa15
commit 42ff1f762f
2 changed files with 83 additions and 67 deletions

View File

@@ -175,8 +175,8 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
[Op.and]: geoSearchQueryPart [Op.and]: geoSearchQueryPart
}; };
//Every other attribute is checked separately and included in query only if it is defined //Every other attribute is checked separately and included in query only if it is defined/not null
if (gardenSizeMax && gardenSizeMin) { if (gardenSizeMax!=null && gardenSizeMin!=null) {
query.gardenSize = { query.gardenSize = {
[Op.lte]: gardenSizeMax, [Op.lte]: gardenSizeMax,
[Op.gte]: gardenSizeMin [Op.gte]: gardenSizeMin
@@ -192,7 +192,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (numberOfRoomsMin && numberOfRoomsMax) { if (numberOfRoomsMin!=null && numberOfRoomsMax!=null) {
query.numberOfRooms = { query.numberOfRooms = {
[Op.lte]: numberOfRoomsMax, [Op.lte]: numberOfRoomsMax,
[Op.gte]: numberOfRoomsMin [Op.gte]: numberOfRoomsMin
@@ -208,7 +208,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (numberOfFloorsMin && numberOfFloorsMax) { if (numberOfFloorsMin!=null && numberOfFloorsMax!=null) {
query.numberOfFloors = { query.numberOfFloors = {
[Op.lte]: numberOfFloorsMax, [Op.lte]: numberOfFloorsMax,
[Op.gte]: numberOfFloorsMin [Op.gte]: numberOfFloorsMin
@@ -224,7 +224,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (floorMin && floorMax) { if (floorMin!=null && floorMax!=null) {
query.floor = { query.floor = {
[Op.lte]: floorMax, [Op.lte]: floorMax,
[Op.gte]: floorMin [Op.gte]: floorMin
@@ -240,7 +240,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (balcony) { if (balcony!=null) {
query.balcony = { query.balcony = {
[Op.eq]: balcony [Op.eq]: balcony
}; };
@@ -252,7 +252,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (newBuilding) { if (newBuilding!=null) {
query.newBuilding = { query.newBuilding = {
[Op.eq]: newBuilding [Op.eq]: newBuilding
}; };
@@ -264,7 +264,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (elevator) { if (elevator!=null) {
query.elevator = { query.elevator = {
[Op.eq]: elevator [Op.eq]: elevator
}; };

View File

@@ -61,10 +61,10 @@ const findSearchRequestsForRealEstate = async realEstate => {
//Needed to decide on including incomplete RealEstates data //Needed to decide on including incomplete RealEstates data
let checkForIncompleteWanted = false; let checkForIncompleteWanted = false;
//Attributes are checked separately and included in query only if defined //Attributes are checked separately and included in query only if defined - not null
//Price and area should be defined for every property
if (price) { //Price and area should be defined for every property
if (price != null) {
query.priceMin = { query.priceMin = {
[Op.lte]: price [Op.lte]: price
}; };
@@ -73,7 +73,7 @@ const findSearchRequestsForRealEstate = async realEstate => {
}; };
} }
if (area) { if (area != null) {
query.sizeMin = { query.sizeMin = {
[Op.lte]: area [Op.lte]: area
}; };
@@ -84,51 +84,61 @@ const findSearchRequestsForRealEstate = async realEstate => {
checkForIncompleteWanted = true; checkForIncompleteWanted = true;
} }
//Other attributes can be defined or not depending on RealEstate type //Other attributes can be defined or not depending on RealEstate type
if (gardenSize) { //we check what to include in query based on real estate type object
query.gardenSizeMin = { if (realEstateTypeObject.hasGardenSize) {
[Op.lte]: gardenSize if (gardenSize != null) {
}; query.gardenSizeMin = {
query.gardenSizeMax = { [Op.lte]: gardenSize
[Op.gte]: gardenSize };
}; query.gardenSizeMax = {
} else if (realEstateTypeObject.hasGardenSize) { [Op.gte]: gardenSize
checkForIncompleteWanted = true; };
} else {
checkForIncompleteWanted = true;
}
} }
if (numberOfRooms) { if (realEstateTypeObject.hasNumberOfRoom) {
query.numberOfRoomsMin = { if (numberOfRooms != null) {
[Op.lte]: numberOfRooms query.numberOfRoomsMin = {
}; [Op.lte]: numberOfRooms
query.numberOfRoomsMax = { };
[Op.gte]: numberOfRooms query.numberOfRoomsMax = {
}; [Op.gte]: numberOfRooms
} else if (realEstateTypeObject.hasNumberOfRoom) { };
checkForIncompleteWanted = true; } else {
checkForIncompleteWanted = true;
}
} }
if (numberOfFloors) { if (realEstateTypeObject.hasNumberOfFloors) {
query.numberOfFloorsMin = { if (numberOfFloors != null) {
[Op.lte]: numberOfFloors query.numberOfFloorsMin = {
}; [Op.lte]: numberOfFloors
query.numberOfFloorsMax = { };
[Op.gte]: numberOfFloors query.numberOfFloorsMax = {
}; [Op.gte]: numberOfFloors
} else if (realEstateTypeObject.hasNumberOfFloors) { };
checkForIncompleteWanted = true; } else {
checkForIncompleteWanted = true;
}
} }
if (floor) { if (realEstateTypeObject.hasFloorProp) {
query.floorMin = { if (floor != null) {
[Op.lte]: floor query.floorMin = {
}; [Op.lte]: floor
query.floorMax = { };
[Op.gte]: floor query.floorMax = {
}; [Op.gte]: floor
} else if (realEstateTypeObject.hasFloorProp) { };
checkForIncompleteWanted = true; } else {
checkForIncompleteWanted = true;
}
} }
if (accessRoadType) { //AccessRoadType is defined - should exits for each ad and estate type
if (accessRoadType != null) {
query.accessRoadType = { query.accessRoadType = {
[Op.or]: { [Op.or]: {
[Op.eq]: "ANY", [Op.eq]: "ANY",
@@ -139,28 +149,34 @@ const findSearchRequestsForRealEstate = async realEstate => {
checkForIncompleteWanted = true; checkForIncompleteWanted = true;
} }
if (balcony) { if (realEstateTypeObject.hasBalconyProp) {
query.balcony = { if (balcony != null) {
[Op.eq]: balcony query.balcony = {
}; [Op.eq]: balcony
} else if (realEstateTypeObject.hasBalconyProp) { };
checkForIncompleteWanted = true; } else {
checkForIncompleteWanted = true;
}
} }
if (newBuilding) { if (realEstateTypeObject.hasNewBuildingProp) {
query.newBuilding = { if (newBuilding != null) {
[Op.eq]: newBuilding query.newBuilding = {
}; [Op.eq]: newBuilding
} else if (realEstateTypeObject.hasNewBuildingProp) { };
checkForIncompleteWanted = true; } else {
checkForIncompleteWanted = true;
}
} }
if (elevator) { if (realEstateTypeObject.hasElevatorProp) {
query.elevator = { if (elevator != null) {
[Op.eq]: elevator query.elevator = {
}; [Op.eq]: elevator
} else if (realEstateTypeObject.hasElevatorProp) { };
checkForIncompleteWanted = true; } else {
checkForIncompleteWanted = true;
}
} }
//If one of the attributes that exists for property type is null //If one of the attributes that exists for property type is null