From cb52c8592adadce838eed82ac6958d1b2cf54a7e Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Sun, 8 Dec 2019 00:58:06 +0100 Subject: [PATCH 1/4] Moved API Google Map key to env variables. --- app/config/appConfig.js | 5 ++++- app/views/location.ejs | 2 +- development.env | 3 +++ tmp.env | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tmp.env diff --git a/app/config/appConfig.js b/app/config/appConfig.js index 0ed1e6b..ec9f851 100644 --- a/app/config/appConfig.js +++ b/app/config/appConfig.js @@ -30,6 +30,8 @@ const MAX_REAL_ESTATES_IN_FIRST_EMAIL = const PRINT_CRAWLER_DEBUG = process.env.PRINT_CRAWLER_DEBUG_INFO || 0; +const API_MAP_KEY= process.env.API_MAP_KEY || ""; + module.exports = { APP_PORT, APP_URL, @@ -39,5 +41,6 @@ module.exports = { AWS_EMAIL_CONFIG, MAX_REAL_ESTATES_IN_EMAIL, MAX_REAL_ESTATES_IN_FIRST_EMAIL, - PRINT_CRAWLER_DEBUG + PRINT_CRAWLER_DEBUG, + API_MAP_KEY }; diff --git a/app/views/location.ejs b/app/views/location.ejs index 5347281..01a25ef 100644 --- a/app/views/location.ejs +++ b/app/views/location.ejs @@ -177,5 +177,5 @@ }); }); - diff --git a/development.env b/development.env index 3a63a34..89f0a1e 100644 --- a/development.env +++ b/development.env @@ -14,6 +14,9 @@ MAX_REAL_ESTATES_IN_FIRST_EMAIL=Max number of real estates that will be shown in #=============== GOOGLE ANALYTICS =============# GA_ID=Google Analytics ID +#=============== GOOGLE MAPS =============# +API_MAP_KEY=(your-key-here) + #=============== AWS SDK EMAIL SETTINGS =======# AWS_KEY_ID=(your-key-here) AWS_SECRET_ACCESS_KEY=(your-key-here) diff --git a/tmp.env b/tmp.env new file mode 100644 index 0000000..456f11b --- /dev/null +++ b/tmp.env @@ -0,0 +1 @@ +API_MAP_KEY="AIzaSyBuqZ6MWvDrquwc-TN6rPS6188D608Zj3Q" \ No newline at end of file From 43074b6eb3816d0e6fc5eb0ecdea78da3afb33e8 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Sun, 8 Dec 2019 22:16:31 +0100 Subject: [PATCH 2/4] Finished map key to env --- tmp.env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tmp.env diff --git a/tmp.env b/tmp.env deleted file mode 100644 index 456f11b..0000000 --- a/tmp.env +++ /dev/null @@ -1 +0,0 @@ -API_MAP_KEY="AIzaSyBuqZ6MWvDrquwc-TN6rPS6188D608Zj3Q" \ No newline at end of file From a45a0ec361791373b3744e795d88facf99d0d3b4 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 16 Dec 2019 21:39:26 +0100 Subject: [PATCH 3/4] apply prettier --- app/config/appConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/appConfig.js b/app/config/appConfig.js index ec9f851..7a7887b 100644 --- a/app/config/appConfig.js +++ b/app/config/appConfig.js @@ -30,7 +30,7 @@ const MAX_REAL_ESTATES_IN_FIRST_EMAIL = const PRINT_CRAWLER_DEBUG = process.env.PRINT_CRAWLER_DEBUG_INFO || 0; -const API_MAP_KEY= process.env.API_MAP_KEY || ""; +const API_MAP_KEY = process.env.API_MAP_KEY || ""; module.exports = { APP_PORT, From 76f4ed0a301961346e18484da8418ce3b8650896 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 16 Dec 2019 22:04:37 +0100 Subject: [PATCH 4/4] apply prettier --- app/controllers/realEstateFilters.js | 1 - app/helpers/db/realEstate.js | 97 ++++++++++++++-------------- app/helpers/db/searchRequest.js | 16 ++--- 3 files changed, 55 insertions(+), 59 deletions(-) diff --git a/app/controllers/realEstateFilters.js b/app/controllers/realEstateFilters.js index ab9eed4..17f5e58 100644 --- a/app/controllers/realEstateFilters.js +++ b/app/controllers/realEstateFilters.js @@ -120,7 +120,6 @@ const getFilters = async (req, res) => { }; const postFilters = async (req, res) => { - const searchRequest = await currentSearchRequest(req); if (!searchRequest || !searchRequest.dataValues) { diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index 9dd4dfe..5d37167 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -131,42 +131,42 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { //General queries contain only attributes that are defined for every searchreq - //Query for case of complete ads + //Query for case of complete ads const query = { - adType, - realEstateType, - price: { - [Op.lte]: priceMax, - [Op.gte]: priceMin - }, - area: { - [Op.lte]: sizeMax, - [Op.gte]: sizeMin - }, - accessRoadType: { - [Op.or]: { - [Op.eq]: 'ANY', - [Op.eq]: accessRoadType - } - }, - [Op.and]: geoSearchQueryPart - } - + adType, + realEstateType, + price: { + [Op.lte]: priceMax, + [Op.gte]: priceMin + }, + area: { + [Op.lte]: sizeMax, + [Op.gte]: sizeMin + }, + accessRoadType: { + [Op.or]: { + [Op.eq]: "ANY", + [Op.eq]: accessRoadType + } + }, + [Op.and]: geoSearchQueryPart + }; + //Query for case of incomplete ads const queryIncludeIncomplete = { adType, realEstateType, price: { - [Op.or] : { - [Op.and] : { + [Op.or]: { + [Op.and]: { [Op.lte]: priceMax, [Op.gte]: priceMin }, - [Op.is] : null + [Op.is]: null } }, area: { - [Op.or] : { + [Op.or]: { [Op.and]: { [Op.lte]: sizeMax, [Op.gte]: sizeMin @@ -176,118 +176,118 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { }, accessRoadType: { [Op.or]: { - [Op.eq]: 'ANY', + [Op.eq]: "ANY", [Op.eq]: accessRoadType, [Op.is]: null } }, [Op.and]: geoSearchQueryPart - } + }; //Every other attribute is checked separately and included in query only if it is defined if (gardenSizeMax && gardenSizeMin) { query.gardenSize = { [Op.lte]: gardenSizeMax, [Op.gte]: gardenSizeMin - } + }; queryIncludeIncomplete.gardenSize = { - [Op.or] : { + [Op.or]: { [Op.and]: { [Op.lte]: gardenSizeMax, [Op.gte]: gardenSizeMin }, [Op.is]: null } - } + }; } if (numberOfRoomsMin && numberOfRoomsMax) { query.numberOfRooms = { [Op.lte]: numberOfRoomsMax, [Op.gte]: numberOfRoomsMin - } + }; queryIncludeIncomplete.numberOfRooms = { - [Op.or] : { + [Op.or]: { [Op.and]: { [Op.lte]: numberOfRoomsMax, [Op.gte]: numberOfRoomsMin }, [Op.is]: null } - } + }; } - + if (numberOfFloorsMin && numberOfFloorsMax) { query.numberOfFloors = { [Op.lte]: numberOfFloorsMax, [Op.gte]: numberOfFloorsMin - } + }; queryIncludeIncomplete.numberOfFloors = { - [Op.or] : { + [Op.or]: { [Op.and]: { [Op.lte]: numberOfFloorsMax, [Op.gte]: numberOfFloorsMin }, [Op.is]: null } - } + }; } if (floorMin && floorMax) { query.floor = { [Op.lte]: floorMax, [Op.gte]: floorMin - } + }; queryIncludeIncomplete.floor = { - [Op.or] : { + [Op.or]: { [Op.and]: { [Op.lte]: floorMax, [Op.gte]: floorMin }, [Op.is]: null } - } + }; } if (balcony) { query.balcony = { [Op.eq]: balcony - } + }; queryIncludeIncomplete.balcony = { [Op.or]: { [Op.eq]: balcony, [Op.is]: null } - } + }; } - + if (newBuilding) { query.newBuilding = { [Op.eq]: newBuilding - } + }; queryIncludeIncomplete.newBuilding = { [Op.or]: { [Op.eq]: newBuilding, [Op.is]: null } - } + }; } - + if (elevator) { query.elevator = { [Op.eq]: elevator - } + }; queryIncludeIncomplete.elevator = { [Op.or]: { [Op.eq]: elevator, [Op.is]: null } - } + }; } const order = [["updatedAt", "desc"]]; - if(!includeIncompleteAds) { + if (!includeIncompleteAds) { return await db.RealEstate.findAll({ where: query, limit: maxResults, @@ -300,7 +300,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => { order }); } - }; module.exports = { diff --git a/app/helpers/db/searchRequest.js b/app/helpers/db/searchRequest.js index 54faeb3..bbb7cc0 100644 --- a/app/helpers/db/searchRequest.js +++ b/app/helpers/db/searchRequest.js @@ -5,11 +5,9 @@ const Op = sequelize.Op; const getSearchRequest = async searchRequestId => { try { - return await db.SearchRequest.findByPk(searchRequestId); - } catch (error) { - console.log("searchrequest.js",error); + console.log("searchrequest.js", error); return null; } }; @@ -116,30 +114,30 @@ const findSearchRequestsForRealEstate = async realEstate => { if (accessRoadType) { query.accessRoadType = { [Op.or]: { - [Op.eq]: 'ANY', + [Op.eq]: "ANY", [Op.eq]: accessRoadType } - } + }; } if (balcony) { query.balcony = { [Op.eq]: balcony - } + }; } if (newBuilding) { query.newBuilding = { [Op.eq]: newBuilding - } + }; } if (elevator) { query.elevator = { [Op.eq]: elevator - } + }; } - + return await db.SearchRequest.findAll({ where: query }); };