From bd33a6b80e3c13706b598acd7cffc84dd6c66cb1 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Mon, 17 Feb 2020 23:24:55 +0100 Subject: [PATCH 1/3] Logs for query check. --- app/helpers/db/searchRequest.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index b6b852e..87147e8 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -35,6 +35,9 @@ const findSearchRequestsForRealEstate = async realEstate => { floor } = realEstate; + // + console.log("New realestate:", realEstate); + if (!locationLat || !locationLong) { return []; } @@ -451,6 +454,9 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } + // + console.log("Query for search of req:", query); + return await db.SearchRequest.findAll({ where: query }); -- 2.47.3 From 7302edceec1d4fa52da0c63e002a767eb3a8a81f Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 18 Feb 2020 15:04:26 +0100 Subject: [PATCH 2/3] Changed queries logic again. --- app/helpers/db/searchRequest.js | 184 ++++++-------------------------- 1 file changed, 34 insertions(+), 150 deletions(-) diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index 87147e8..c6c0fbb 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -35,8 +35,8 @@ const findSearchRequestsForRealEstate = async realEstate => { floor } = realEstate; - // - console.log("New realestate:", realEstate); + //Debugging log + console.log("New realestate:", realEstate.dataValues); if (!locationLat || !locationLong) { return []; @@ -159,33 +159,11 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } else { // 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 (or default) + //It returns all search requests except for ones that dont want incpomlete ads numberOfRoomsQuery = { - [Op.or]: [ - { - [Op.and]: [ - { - numberOfRoomsMin: { - [Op.is]: null - } - }, - { - numberOfRoomsMax: { - [Op.is]: null - } - } - ] - }, - { - includeIncompleteAds: { - [Op.or]: { - [Op.eq]: true, - [Op.is]: null - } - } - } - ] + includeIncompleteAds: { + [Op.ne]: false + } }; } } @@ -215,30 +193,9 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } else { numberOfFloorsQuery = { - [Op.or]: [ - { - [Op.and]: [ - { - numberOfFloorsMin: { - [Op.is]: null - } - }, - { - numberOfFloorsMax: { - [Op.is]: null - } - } - ] - }, - { - includeIncompleteAds: { - [Op.or]: { - [Op.eq]: true, - [Op.is]: null - } - } - } - ] + includeIncompleteAds: { + [Op.ne]: false + } }; } } @@ -267,30 +224,9 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } else { floorQuery = { - [Op.or]: [ - { - [Op.and]: [ - { - floorMin: { - [Op.is]: null - } - }, - { - floorMax: { - [Op.is]: null - } - } - ] - }, - { - includeIncompleteAds: { - [Op.or]: { - [Op.eq]: true, - [Op.is]: null - } - } - } - ] + includeIncompleteAds: { + [Op.ne]: false + } }; } } @@ -299,7 +235,7 @@ const findSearchRequestsForRealEstate = async realEstate => { //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 + //If real estate characteristic = null, dont know if true or false, find all req except ones that dont want incomplete ads let balconyQuery = {}; if (realEstateTypeObject.hasBalconyProp && balcony !== true) { if (balcony === false) { @@ -310,30 +246,9 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } else if (balcony === null) { balconyQuery = { - [Op.or]: [ - { - balcony: { - [Op.ne]: true - } - }, - { - [Op.and]: [ - { - balcony: { - [Op.eq]: true - } - }, - { - includeIncompleteAds: { - [Op.or]: { - [Op.eq]: true, - [Op.is]: null - } - } - } - ] - } - ] + includeIncompleteAds: { + [Op.ne]: false + } }; } } @@ -347,30 +262,9 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } else if (newBuilding === null) { newBuildingQuery = { - [Op.or]: [ - { - newBuilding: { - [Op.ne]: true - } - }, - { - [Op.and]: [ - { - newBuilding: { - [Op.eq]: true - } - }, - { - includeIncompleteAds: { - [Op.or]: { - [Op.eq]: true, - [Op.is]: null - } - } - } - ] - } - ] + includeIncompleteAds: { + [Op.ne]: false + } }; } } @@ -384,33 +278,13 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } else if (elevator === null) { elevatorQuery = { - [Op.or]: [ - { - elevator: { - [Op.ne]: true - } - }, - { - [Op.and]: [ - { - elevator: { - [Op.eq]: true - } - }, - { - includeIncompleteAds: { - [Op.or]: { - [Op.eq]: true, - [Op.is]: null - } - } - } - ] - } - ] + includeIncompleteAds: { + [Op.ne]: false + } }; } } + //General query consists of each individual query const query = { adType, @@ -454,8 +328,18 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } - // + //Debugging logs console.log("Query for search of req:", query); + console.log("Price", priceQuery); + console.log("Area", areaQuery); + console.log("Garden", gardenSizeQuery); + console.log("Number of rooms", numberOfRoomsQuery); + console.log("Number offloors", numberOfFloorsQuery); + console.log("Floor", floorQuery); + console.log("Balcony", balconyQuery); + console.log("New building", newBuildingQuery); + console.log("Elevator", elevatorQuery); + // return await db.SearchRequest.findAll({ where: query -- 2.47.3 From 6bad24d73512337578799cc5c8c8f05f34b0838a Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 21 Feb 2020 14:25:10 +0100 Subject: [PATCH 3/3] New query for search req search. --- app/helpers/db/searchRequest.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index c6c0fbb..0064bdd 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -35,9 +35,6 @@ const findSearchRequestsForRealEstate = async realEstate => { floor } = realEstate; - //Debugging log - console.log("New realestate:", realEstate.dataValues); - if (!locationLat || !locationLong) { return []; } @@ -328,19 +325,6 @@ const findSearchRequestsForRealEstate = async realEstate => { }; } - //Debugging logs - console.log("Query for search of req:", query); - console.log("Price", priceQuery); - console.log("Area", areaQuery); - console.log("Garden", gardenSizeQuery); - console.log("Number of rooms", numberOfRoomsQuery); - console.log("Number offloors", numberOfFloorsQuery); - console.log("Floor", floorQuery); - console.log("Balcony", balconyQuery); - console.log("New building", newBuildingQuery); - console.log("Elevator", elevatorQuery); - // - return await db.SearchRequest.findAll({ where: query }); -- 2.47.3