WIP Changed all logic for searchRequest.
This commit is contained in:
@@ -104,6 +104,9 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
accessRoadType
|
||||
} = searchRequest;
|
||||
|
||||
// ++ testing
|
||||
console.log("SearchRequest za koji trazimo:", searchRequest);
|
||||
|
||||
//Needed for defining which attribute should exist or not
|
||||
const realEstateTypeObject = AD_CATEGORY[realEstateType];
|
||||
|
||||
@@ -202,7 +205,11 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (realEstateTypeObject.hasNumberOfRoom && numberOfRoomsMin != null && numberOfRoomsMax != null) {
|
||||
if (
|
||||
realEstateTypeObject.hasNumberOfRoom &&
|
||||
numberOfRoomsMin != null &&
|
||||
numberOfRoomsMax != null
|
||||
) {
|
||||
query.numberOfRooms = {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
@@ -218,7 +225,11 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (realEstateTypeObject.hasNumberOfFloors && numberOfFloorsMin != null && numberOfFloorsMax != null) {
|
||||
if (
|
||||
realEstateTypeObject.hasNumberOfFloors &&
|
||||
numberOfFloorsMin != null &&
|
||||
numberOfFloorsMax != null
|
||||
) {
|
||||
query.numberOfFloors = {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
@@ -234,7 +245,11 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (realEstateTypeObject.hasFloorProp && floorMin != null && floorMax != null) {
|
||||
if (
|
||||
realEstateTypeObject.hasFloorProp &&
|
||||
floorMin != null &&
|
||||
floorMax != null
|
||||
) {
|
||||
query.floor = {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
@@ -249,8 +264,10 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (realEstateTypeObject.hasBalconyProp && balcony != null) {
|
||||
//Logic for balcony, newBuilding and elevator from users side
|
||||
//If true is checked, then I want characteristic to be true but,
|
||||
//if it is not checked, then I dont care - it can be null or false or true
|
||||
if (realEstateTypeObject.hasBalconyProp && balcony === true) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
};
|
||||
@@ -262,7 +279,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (realEstateTypeObject.hasNewBuildingProp && newBuilding != null) {
|
||||
if (realEstateTypeObject.hasNewBuildingProp && newBuilding === true) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
};
|
||||
@@ -274,7 +291,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (realEstateTypeObject.hasElevatorProp && elevator != null) {
|
||||
if (realEstateTypeObject.hasElevatorProp && elevator === true) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
};
|
||||
@@ -301,6 +318,12 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
|
||||
const order = [["updatedAt", "desc"]];
|
||||
|
||||
//++
|
||||
console.log(
|
||||
"Query user to find real estates:",
|
||||
includeIncompleteAds ? queryIncludeIncomplete : query
|
||||
);
|
||||
|
||||
return db.RealEstate.findAll({
|
||||
where: includeIncompleteAds ? queryIncludeIncomplete : query,
|
||||
limit: maxResults,
|
||||
|
||||
Reference in New Issue
Block a user