From 5b3491fdba0e3551dea0bbab3e7c55125b5ee0c9 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 23 Jan 2020 10:12:56 +0100 Subject: [PATCH 1/3] Added migration and model change for searchReq table. --- .prettierignore | 1 + app/controllers/realEstateFilters.js | 8 ++++++-- ...-includeWithoutPrice-to-searchRequests-table.js | 14 ++++++++++++++ app/models/searchRequest.js | 11 ++++++++++- app/views/standardFilters.ejs | 10 ++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 .prettierignore create mode 100644 app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..82435b1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.ejs \ No newline at end of file diff --git a/app/controllers/realEstateFilters.js b/app/controllers/realEstateFilters.js index 17f5e58..252ac46 100644 --- a/app/controllers/realEstateFilters.js +++ b/app/controllers/realEstateFilters.js @@ -35,7 +35,8 @@ const getFilters = async (req, res) => { balcony, elevator, newBuilding, - accessRoadType + accessRoadType, + includeWithoutPrice } = searchRequest; const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT; @@ -115,7 +116,8 @@ const getFilters = async (req, res) => { advancedSegmentSelectFilterValues, advancedRangeFilterObjects, advancedRangeFilterValues, - includeIncompleteAds + includeIncompleteAds, + includeWithoutPrice }); }; @@ -191,6 +193,7 @@ const postFilters = async (req, res) => { }); const includeIncompleteAds = req.body.includeIncompleteAds === "on"; + const includeWithoutPrice = req.body.includeWithoutPrice === "on"; const balcony = req.body.balcony === "on"; const elevator = req.body.elevator === "on"; @@ -217,6 +220,7 @@ const postFilters = async (req, res) => { searchRequest.newBuilding = newBuilding; searchRequest.includeIncompleteAds = includeIncompleteAds; + searchRequest.includeWithoutPrice = includeWithoutPrice; searchRequest.accessRoadType = accessRoadType; diff --git a/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js b/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js new file mode 100644 index 0000000..c118d92 --- /dev/null +++ b/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js @@ -0,0 +1,14 @@ +"use strict"; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.addColumn("SearchRequests", "includeWithoutPrice", { + type: Sequelize.BOOLEAN, + defaultValue: false + }); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.removeColumn("SearchRequests", "includeWithoutPrice"); + } +}; diff --git a/app/models/searchRequest.js b/app/models/searchRequest.js index 8a04593..0d4997f 100644 --- a/app/models/searchRequest.js +++ b/app/models/searchRequest.js @@ -15,7 +15,15 @@ module.exports = (sequelize, DataTypes) => { allowNull: false, defaultValue: { type: "Polygon", - coordinates: [[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]], + coordinates: [ + [ + [0, 0], + [0, 0], + [0, 0], + [0, 0], + [0, 0] + ] + ], crs: { type: "name", properties: { name: "EPSG:4326" } } } }, @@ -71,6 +79,7 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.TEXT }, includeIncompleteAds: DataTypes.BOOLEAN, + includeWithoutPrice: DataTypes.BOOLEAN, balcony: DataTypes.BOOLEAN, elevator: DataTypes.BOOLEAN, newBuilding: DataTypes.BOOLEAN, diff --git a/app/views/standardFilters.ejs b/app/views/standardFilters.ejs index 27a6bba..e0526b4 100644 --- a/app/views/standardFilters.ejs +++ b/app/views/standardFilters.ejs @@ -18,6 +18,16 @@ +
+

+ +


-- 2.47.3 From 98263364c723ff3a5ee8f02179c490982a7ad74c Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 23 Jan 2020 11:13:53 +0100 Subject: [PATCH 2/3] Added option to include-exclude ads without price --- app/helpers/db/realEstate.js | 55 ++++++++++++++++++++++----------- app/helpers/db/searchRequest.js | 9 +++++- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index c4c2d74..0d59674 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -98,6 +98,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { floorMin, floorMax, includeIncompleteAds, + includeWithoutPrice, balcony, elevator, newBuilding, @@ -139,15 +140,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { const query = { adType, realEstateType, - price: { - [Op.or]: { - [Op.and]: { - [Op.lte]: priceMax, - [Op.gte]: priceMin - }, - [Op.is]: null - } - }, area: { [Op.lte]: sizeMax, [Op.gte]: sizeMin @@ -159,15 +151,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { const queryIncludeIncomplete = { adType, realEstateType, - price: { - [Op.or]: { - [Op.and]: { - [Op.lte]: priceMax, - [Op.gte]: priceMin - }, - [Op.is]: null - } - }, area: { [Op.or]: { [Op.and]: { @@ -180,6 +163,42 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { [Op.and]: geoSearchQueryPart }; + //Is user checked includeWithoutPrice TRUE then it should return null values of price + //If not then only check for price max and min (this is DEFAULT) + //includeIncpompleteAds does not have effect on price query + if (includeWithoutPrice) { + query.price = { + [Op.or]: { + [Op.and]: { + [Op.lte]: priceMax, + [Op.gte]: priceMin + }, + [Op.is]: null + } + }; + queryIncludeIncomplete.price = { + [Op.or]: { + [Op.and]: { + [Op.lte]: priceMax, + [Op.gte]: priceMin + }, + [Op.is]: null + } + }; + } else { + query.price = { + [Op.and]: { + [Op.lte]: priceMax, + [Op.gte]: priceMin + } + }; + queryIncludeIncomplete.price = { + [Op.and]: { + [Op.lte]: priceMax, + [Op.gte]: priceMin + } + }; + } //Every other attribute is checked separately and included in query only if it is defined for real estate type if ( diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index 32eb54f..e2633b4 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -57,7 +57,8 @@ const findSearchRequestsForRealEstate = async realEstate => { //Attributes are checked separately to make different query parts - //If price is null it will be excluded from query - it will show properties with null price values + //If real estate price is number then it searches for req that have priceMin and priceMax + //If real estate price is null it searches for req that accept ads without price //User always defines price and area (sliders) - not null in search req let priceQuery = {}; if (price != null) { @@ -75,6 +76,12 @@ const findSearchRequestsForRealEstate = async realEstate => { } ] }; + } else { + priceQuery = { + includeWithoutPrice: { + [Op.eq]: true + } + }; } let areaQuery = {}; -- 2.47.3 From fa46f75dd329b501afac0a75efc935900250626c Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 28 Jan 2020 22:28:52 +0100 Subject: [PATCH 3/3] Changed default to switched on. --- app/helpers/db/realEstate.js | 4 ++-- ...add-column-includeWithoutPrice-to-searchRequests-table.js | 2 +- app/views/standardFilters.ejs | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index 0d59674..0f77260 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -163,8 +163,8 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { [Op.and]: geoSearchQueryPart }; - //Is user checked includeWithoutPrice TRUE then it should return null values of price - //If not then only check for price max and min (this is DEFAULT) + //Is user unchecked includeWithoutPrice FALSE then it shouldn't return null values of price + //If not then null values are accepted (this is DEFAULT) //includeIncpompleteAds does not have effect on price query if (includeWithoutPrice) { query.price = { diff --git a/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js b/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js index c118d92..9173829 100644 --- a/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js +++ b/app/migrations/20200123085754-add-column-includeWithoutPrice-to-searchRequests-table.js @@ -4,7 +4,7 @@ module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.addColumn("SearchRequests", "includeWithoutPrice", { type: Sequelize.BOOLEAN, - defaultValue: false + defaultValue: true }); }, diff --git a/app/views/standardFilters.ejs b/app/views/standardFilters.ejs index e0526b4..43b931a 100644 --- a/app/views/standardFilters.ejs +++ b/app/views/standardFilters.ejs @@ -22,9 +22,8 @@

-- 2.47.3