From 7302edceec1d4fa52da0c63e002a767eb3a8a81f Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 18 Feb 2020 15:04:26 +0100 Subject: [PATCH] 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