From 42ff1f762ff3a5f0966ea783e8a90d6f2b823e4c Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Sat, 21 Dec 2019 02:20:26 +0100 Subject: [PATCH 1/4] Changed to avoid falsy values and not defined realestate parametrs. --- app/helpers/db/realEstate.js | 16 ++-- app/helpers/db/searchRequest.js | 134 ++++++++++++++++++-------------- 2 files changed, 83 insertions(+), 67 deletions(-) diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index ebeb84c..55068da 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -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 }; diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index 808637a..4596fd5 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -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 -- 2.47.3 From d5d3a1f306fdfca8238db556937113d07d7ec13f Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 26 Dec 2019 23:30:05 +0100 Subject: [PATCH 2/4] Changed accesRoadType logic --- app/helpers/db/realEstate.js | 29 ++++++++++++++++++++--------- app/helpers/db/searchRequest.js | 9 ++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index 55068da..2abac03 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -2,6 +2,8 @@ const db = require("../../models/index"); const sequelize = require("sequelize"); const Op = sequelize.Op; +const { AD_CATEGORY } = require("../../common/enums"); + const bulkUpsertRealEstates = async realEstateData => { try { const fieldsToUpdateIfDuplicate = [ @@ -102,6 +104,9 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { accessRoadType } = searchRequest; + //Needed for defining which attribute should exist or not + const realEstateTypeObject = AD_CATEGORY[realEstateType]; + const longitudeColumn = sequelize.col("locationLong"); const latitudeColumn = sequelize.col("locationLat"); @@ -175,8 +180,13 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { [Op.and]: geoSearchQueryPart }; - //Every other attribute is checked separately and included in query only if it is defined/not null - if (gardenSizeMax!=null && gardenSizeMin!=null) { + //Every other attribute is checked separately and included in query only if it is defined for real estate type + + if ( + realEstateTypeObject.hasGardenSize && + gardenSizeMax != null && + gardenSizeMin != null + ) { query.gardenSize = { [Op.lte]: gardenSizeMax, [Op.gte]: gardenSizeMin @@ -192,7 +202,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }; } - if (numberOfRoomsMin!=null && numberOfRoomsMax!=null) { + if (realEstateTypeObject.hasNumberOfRoom && numberOfRoomsMin != null && numberOfRoomsMax != null) { query.numberOfRooms = { [Op.lte]: numberOfRoomsMax, [Op.gte]: numberOfRoomsMin @@ -208,7 +218,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }; } - if (numberOfFloorsMin!=null && numberOfFloorsMax!=null) { + if (realEstateTypeObject.hasNumberOfFloors && numberOfFloorsMin != null && numberOfFloorsMax != null) { query.numberOfFloors = { [Op.lte]: numberOfFloorsMax, [Op.gte]: numberOfFloorsMin @@ -224,7 +234,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }; } - if (floorMin!=null && floorMax!=null) { + if (realEstateTypeObject.hasFloorProp && floorMin != null && floorMax != null) { query.floor = { [Op.lte]: floorMax, [Op.gte]: floorMin @@ -240,7 +250,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }; } - if (balcony!=null) { + if (realEstateTypeObject.hasBalconyProp && balcony != null) { query.balcony = { [Op.eq]: balcony }; @@ -252,7 +262,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }; } - if (newBuilding!=null) { + if (realEstateTypeObject.hasNewBuildingProp && newBuilding != null) { query.newBuilding = { [Op.eq]: newBuilding }; @@ -264,7 +274,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }; } - if (elevator!=null) { + if (realEstateTypeObject.hasElevatorProp && elevator != null) { query.elevator = { [Op.eq]: elevator }; @@ -275,7 +285,8 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { } }; } - + //If user wants 'ANY' road type acces then it is not included in query - + //returns every road type and null values if (accessRoadType !== "ANY") { query.accessRoadType = { [Op.eq]: accessRoadType diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index 4596fd5..b3e4e29 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -137,7 +137,7 @@ const findSearchRequestsForRealEstate = async realEstate => { } } - //AccessRoadType is defined - should exits for each ad and estate type + //AccessRoadType is defined - should exists for each ad and estate type if (accessRoadType != null) { query.accessRoadType = { [Op.or]: { @@ -145,8 +145,11 @@ const findSearchRequestsForRealEstate = async realEstate => { [Op.eq]: accessRoadType } }; - } else if (realEstateTypeObject.hasAccesRoadType) { - checkForIncompleteWanted = true; + } else { + //Null values are returned for user request that wanted ANY acces road type + query.accessRoadType = { + [Op.eq]: "ANY" + }; } if (realEstateTypeObject.hasBalconyProp) { -- 2.47.3 From 870b71a3c712d4ed30b5ec9a3cf85436d7456281 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 17 Jan 2020 01:54:06 +0100 Subject: [PATCH 3/4] WIP Changed all logic for searchRequest. --- app/helpers/db/realEstate.js | 37 ++- app/helpers/db/searchRequest.js | 401 ++++++++++++++++++++++------ app/services/notificationService.js | 2 + 3 files changed, 352 insertions(+), 88 deletions(-) diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index 2abac03..87cf07e 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -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, diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index b3e4e29..223ec89 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -49,99 +49,364 @@ const findSearchRequestsForRealEstate = async realEstate => { const geoSearchQueryPart = sequelize.where(contains, true); - //General query contains only attributes that are defined for every RealEstate - not null - const query = { - adType, - realEstateType, - subscribed: true, - [Op.and]: geoSearchQueryPart - }; //Needed for defining which attribute should exist or not const realEstateTypeObject = AD_CATEGORY[realEstateType]; - //Needed to decide on including incomplete RealEstates data + + // ?? Needed to decide on including incomplete RealEstates data let checkForIncompleteWanted = false; - //Attributes are checked separately and included in query only if defined - not null + //Attributes are checked separately to make different query parts - //Price and area should be defined for every property + //If price is null it will be excluded from query - it will show properties with null price values + //User always defines price and area (sliders) - not null in search req + let priceQuery = {}; if (price != null) { - query.priceMin = { - [Op.lte]: price - }; - query.priceMax = { - [Op.gte]: price + priceQuery = { + [Op.and]: [ + { + priceMin: { + [Op.lte]: price + } + }, + { + priceMax: { + [Op.gte]: price + } + } + ] }; } + let areaQuery = {}; if (area != null) { - query.sizeMin = { - [Op.lte]: area - }; - query.sizeMax = { - [Op.gte]: area + areaQuery = { + [Op.and]: [ + { + sizeMin: { + [Op.lte]: area + } + }, + { + sizeMax: { + [Op.gte]: area + } + } + ] }; } else { checkForIncompleteWanted = true; } + //Other attributes can be defined or not depending on RealEstate type //we check what to include in query based on real estate type object + let gardenSizeQuery = {}; if (realEstateTypeObject.hasGardenSize) { if (gardenSize != null) { - query.gardenSizeMin = { - [Op.lte]: gardenSize - }; - query.gardenSizeMax = { - [Op.gte]: gardenSize + gardenSizeQuery = { + [Op.and]: [ + { + gardenSizeMin: { + [Op.lte]: gardenSize + } + }, + { + gardenSizeMax: { + [Op.gte]: gardenSize + } + } + ] }; } else { checkForIncompleteWanted = true; } } + let numberOfRoomsQuery = {}; if (realEstateTypeObject.hasNumberOfRoom) { if (numberOfRooms != null) { - query.numberOfRoomsMin = { - [Op.lte]: numberOfRooms - }; - query.numberOfRoomsMax = { - [Op.gte]: numberOfRooms + //If real estate has defined number of rooms ex. 3 it returns req + // that accepts 3 rooms or ones that don't have defined number - null + //Ex. they didnt choose advanced filters at all + numberOfRoomsQuery = { + [Op.and]: [ + { + numberOfRoomsMin: { + [Op.or]: { + [Op.lte]: numberOfRooms, + [Op.is]: null + } + } + }, + { + numberOfRoomsMax: { + [Op.or]: { + [Op.gte]: numberOfRooms, + [Op.is]: null + } + } + } + ] }; } else { - checkForIncompleteWanted = true; + // If real estate dont have defined number of rooms ex. null + //It returns requests that didn't choose number of rooms - also null + //Or ones that picked some values but also picked to includeIncomplete ads + numberOfRoomsQuery = { + [Op.or]: [ + { + [Op.and]: [ + { + numberOfRoomsMin: { + [Op.is]: null + } + }, + { + numberOfRoomsMax: { + [Op.is]: null + } + } + ] + }, + { + includeIncompleteAds: { + [Op.eq]: true + } + } + ] + }; } } - + //Same logic for number of Floors and floors + let numberOfFloorsQuery = {}; if (realEstateTypeObject.hasNumberOfFloors) { if (numberOfFloors != null) { - query.numberOfFloorsMin = { - [Op.lte]: numberOfFloors - }; - query.numberOfFloorsMax = { - [Op.gte]: numberOfFloors + numberOfFloorsQuery = { + [Op.and]: [ + { + numberOfFloorsMin: { + [Op.or]: { + [Op.lte]: numberOfFloors, + [Op.is]: null + } + } + }, + { + numberOfFloorsMax: { + [Op.or]: { + [Op.gte]: numberOfFloors, + [Op.is]: null + } + } + } + ] }; } else { - checkForIncompleteWanted = true; + numberOfFloorsQuery = { + [Op.or]: [ + { + [Op.and]: [ + { + numberOfFloorsMin: { + [Op.is]: null + } + }, + { + numberOfFloorsMax: { + [Op.is]: null + } + } + ] + }, + { + includeIncompleteAds: { + [Op.eq]: true + } + } + ] + }; + } + } + let floorQuery = {}; + if (realEstateTypeObject.hasFloorProp) { + if (floor != null) { + floorQuery = { + [Op.and]: [ + { + floorMin: { + [Op.or]: { + [Op.lte]: floor, + [Op.is]: null + } + } + }, + { + floorMax: { + [Op.or]: { + [Op.gte]: floor, + [Op.is]: null + } + } + } + ] + }; + } else { + floorQuery = { + [Op.or]: [ + { + [Op.and]: [ + { + floorMin: { + [Op.is]: null + } + }, + { + floorMax: { + [Op.is]: null + } + } + ] + }, + { + includeIncompleteAds: { + [Op.eq]: true + } + } + ] + }; } } - if (realEstateTypeObject.hasFloorProp) { - if (floor != null) { - query.floorMin = { - [Op.lte]: floor + //Logic for balcony, newBuilding and elevator + //If user dont check checkbox for ex. elevator it does not mean he only wants no elevator + //If real estate characteristic =true find all req, one that wants charachertistic or dont care - dont need query + //If real estate characteristic = false, find all req exept for ones that wants characteristic to be true + //If real estate characteristic = null, dont know if true or false, find req that dont care or want char and want incomplete ads + let balconyQuery = {}; + if (realEstateTypeObject.hasBalconyProp && balcony !== true) { + if (balcony === false) { + balconyQuery = { + balcony: { + [Op.ne]: true + } }; - query.floorMax = { - [Op.gte]: floor + } else if (balcony === null) { + balconyQuery = { + [Op.or]: [ + { + balcony: { + [Op.ne]: true + } + }, + { + [Op.and]: [ + { + balcony: { + [Op.eq]: true + } + }, + { + includeIncompleteAds: { + [Op.eq]: true + } + } + ] + } + ] }; - } else { - checkForIncompleteWanted = true; } } + let newBuildingQuery = {}; + if (realEstateTypeObject.hasNewBuildingProp && newBuilding !== true) { + if (newBuilding === false) { + newBuildingQuery = { + newBuilding: { + [Op.ne]: true + } + }; + } else if (newBuilding === null) { + newBuildingQuery = { + [Op.or]: [ + { + newBuilding: { + [Op.ne]: true + } + }, + { + [Op.and]: [ + { + newBuilding: { + [Op.eq]: true + } + }, + { + includeIncompleteAds: { + [Op.eq]: true + } + } + ] + } + ] + }; + } + } + let elevatorQuery = {}; + if (realEstateTypeObject.hasElevatorProp && elevator !== true) { + if (elevator === false) { + elevatorQuery = { + elevator: { + [Op.ne]: true + } + }; + } else if (elevator === null) { + elevatorQuery = { + [Op.or]: [ + { + elevator: { + [Op.ne]: true + } + }, + { + [Op.and]: [ + { + elevator: { + [Op.eq]: true + } + }, + { + includeIncompleteAds: { + [Op.eq]: true + } + } + ] + } + ] + }; + } + } + //General query consists of each individual query + const query = { + adType, + realEstateType, + subscribed: true, + [Op.and]: [ + geoSearchQueryPart, + priceQuery, + areaQuery, + gardenSizeQuery, + numberOfRoomsQuery, + numberOfFloorsQuery, + floorQuery, + balconyQuery, + newBuildingQuery, + elevatorQuery + ] + }; //AccessRoadType is defined - should exists for each ad and estate type if (accessRoadType != null) { query.accessRoadType = { [Op.or]: { - [Op.eq]: "ANY", + [Op.like]: "ANY", [Op.eq]: accessRoadType } }; @@ -151,45 +416,19 @@ const findSearchRequestsForRealEstate = async realEstate => { [Op.eq]: "ANY" }; } - - if (realEstateTypeObject.hasBalconyProp) { - if (balcony != null) { - query.balcony = { - [Op.eq]: balcony - }; - } else { - checkForIncompleteWanted = true; - } - } - - if (realEstateTypeObject.hasNewBuildingProp) { - if (newBuilding != null) { - query.newBuilding = { - [Op.eq]: newBuilding - }; - } else { - 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 - //we include in query to check if incomplete real estates are accepted + //Tag to check if incomplete ads are accepted in query if (checkForIncompleteWanted) { query.includeIncompleteAds = { [Op.eq]: true }; } - return await db.SearchRequest.findAll({ where: query }); + + //++ + console.log("Query koji koristimo:", query); + // + return await db.SearchRequest.findAll({ + where: query + }); }; module.exports = { diff --git a/app/services/notificationService.js b/app/services/notificationService.js index 7495e17..ab9f619 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -12,6 +12,8 @@ const { findNotNotifiedMatches } = require("../helpers/db/searchRequestMatch"); const { sendEmail } = require("../services/emailService"); const notifyForNewRealEstates = async newRealEstates => { + // + console.log("Real estates", newRealEstates); const matches = await matchRealEstates(newRealEstates); await notifyMatches(matches); }; -- 2.47.3 From d117383802167cf9c7ef9b33455bc31c84c9145e Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 17 Jan 2020 22:58:22 +0100 Subject: [PATCH 4/4] Tested both ways for realestate and search req filters. --- app/helpers/db/realEstate.js | 9 --------- app/helpers/db/searchRequest.js | 3 --- app/services/notificationService.js | 2 -- 3 files changed, 14 deletions(-) diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index 87cf07e..c4c2d74 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -104,9 +104,6 @@ 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]; @@ -318,12 +315,6 @@ 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, diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index 223ec89..32eb54f 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -423,9 +423,6 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } - //++ - console.log("Query koji koristimo:", query); - // return await db.SearchRequest.findAll({ where: query }); diff --git a/app/services/notificationService.js b/app/services/notificationService.js index ab9f619..7495e17 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -12,8 +12,6 @@ const { findNotNotifiedMatches } = require("../helpers/db/searchRequestMatch"); const { sendEmail } = require("../services/emailService"); const notifyForNewRealEstates = async newRealEstates => { - // - console.log("Real estates", newRealEstates); const matches = await matchRealEstates(newRealEstates); await notifyMatches(matches); }; -- 2.47.3