From 42ff1f762ff3a5f0966ea783e8a90d6f2b823e4c Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Sat, 21 Dec 2019 02:20:26 +0100 Subject: [PATCH 01/15] 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 From d5d3a1f306fdfca8238db556937113d07d7ec13f Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 26 Dec 2019 23:30:05 +0100 Subject: [PATCH 02/15] 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) { From e6725355a02c2515c07b912a5c89b0b63e159491 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Wed, 15 Jan 2020 01:33:37 +0100 Subject: [PATCH 03/15] Changed sliders for different realestate types. --- app/common/enums.js | 111 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 16 deletions(-) diff --git a/app/common/enums.js b/app/common/enums.js index 33cb41e..2c17eb7 100644 --- a/app/common/enums.js +++ b/app/common/enums.js @@ -7,7 +7,42 @@ const PRICE_SLIDER_OPTIONS_SALE = { step: 1000, connect: true }; - +const FLAT_PRICE_SLIDER_OPTIONS_SALE = { + start: [50000, 150000], + range: { + min: [0], + max: [800000] + }, + step: 5000, + connect: true +}; +const HOUSE_PRICE_SLIDER_OPTIONS_SALE = { + start: [50000, 150000], + range: { + min: [0], + max: [1500000] + }, + step: 10000, + connect: true +}; +const OFFICE_PRICE_SLIDER_OPTIONS_SALE = { + start: [15000, 50000], + range: { + min: [0], + max: [2000000] + }, + step: 2000, + connect: true +}; +const LAND_PRICE_SLIDER_OPTIONS_SALE = { + start: [40000, 80000], + range: { + min: [0], + max: [2000000] + }, + step: 10000, + connect: true +}; const PRICE_SLIDER_OPTIONS_RENT = { start: [300, 500], range: { @@ -17,18 +52,62 @@ const PRICE_SLIDER_OPTIONS_RENT = { step: 50, connect: true }; - +const FLAT_PRICE_SLIDER_OPTIONS_RENT = { + start: [300, 600], + range: { + min: [0], + max: [4000] + }, + step: 100, + connect: true +}; +const HOUSE_PRICE_SLIDER_OPTIONS_RENT = { + start: [500, 1000], + range: { + min: [0], + max: [10000] + }, + step: 100, + connect: true +}; +const OFFICE_PRICE_SLIDER_OPTIONS_RENT = { + start: [200, 1000], + range: { + min: [0], + max: [20000] + }, + step: 100, + connect: true +}; +const LAND_PRICE_SLIDER_OPTIONS_RENT = { + start: [500, 1000], + range: { + min: [0], + max: [20000] + }, + step: 100, + connect: true +}; //This will be used for Flats, Apartments, Houses const HOME_SIZE_SLIDER_OPTIONS = { start: [30, 75], range: { min: [0], - max: [400] + max: [500] }, step: 5, connect: true }; +const OFFICE_SIZE_SLIDER_OPTIONS = { + start: [30, 150], + range: { + min: [0], + max: [1200] + }, + step: 10, + connect: true +}; const GARDEN_SIZE_SLIDER_OPTIONS = { start: [100, 1000], range: { @@ -111,8 +190,8 @@ const AD_CATEGORY = { hasNumberOfRoom: true, hasNumberOfFloors: false, hasFloorProp: true, - priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, - priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, + priceSliderOptionsSale: FLAT_PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: FLAT_PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, HOUSE: { @@ -126,8 +205,8 @@ const AD_CATEGORY = { hasNumberOfRoom: true, hasNumberOfFloors: true, hasFloorProp: false, - priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, - priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, + priceSliderOptionsSale: HOUSE_PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: HOUSE_PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS, gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS }, @@ -142,9 +221,9 @@ const AD_CATEGORY = { hasNumberOfRoom: true, hasNumberOfFloors: false, hasFloorProp: true, - priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, - priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, - sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS + priceSliderOptionsSale: OFFICE_PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: OFFICE_PRICE_SLIDER_OPTIONS_RENT, + sizeSliderOptions: OFFICE_SIZE_SLIDER_OPTIONS }, LAND: { id: "LAND", @@ -157,8 +236,8 @@ const AD_CATEGORY = { hasNumberOfRoom: false, hasNumberOfFloors: false, hasFloorProp: false, - priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, - priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, + priceSliderOptionsSale: LAND_PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: LAND_PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: LAND_SIZE_SLIDER_OPTIONS }, APARTMENT: { @@ -172,8 +251,8 @@ const AD_CATEGORY = { hasNumberOfRoom: true, hasNumberOfFloors: false, hasFloorProp: true, - priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, - priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, + priceSliderOptionsSale: FLAT_PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: FLAT_PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, GARAGE: { @@ -202,8 +281,8 @@ const AD_CATEGORY = { hasNumberOfRoom: true, hasNumberOfFloors: true, hasFloorProp: false, - priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, - priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, + priceSliderOptionsSale: HOUSE_PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: HOUSE_PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS, gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS } From 870b71a3c712d4ed30b5ec9a3cf85436d7456281 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 17 Jan 2020 01:54:06 +0100 Subject: [PATCH 04/15] 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); }; From d117383802167cf9c7ef9b33455bc31c84c9145e Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 17 Jan 2020 22:58:22 +0100 Subject: [PATCH 05/15] 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); }; From 0a181f742f9e4478ffefe4a778108ea5cb95d0cd Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Mon, 20 Jan 2020 23:09:02 +0100 Subject: [PATCH 06/15] WIP Added model and migration for new table priceHistory. --- .../20200120215830-add-priceHistory-table.js | 38 +++++++++++++++++++ app/models/priceHistory.js | 35 +++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 app/migrations/20200120215830-add-priceHistory-table.js create mode 100644 app/models/priceHistory.js diff --git a/app/migrations/20200120215830-add-priceHistory-table.js b/app/migrations/20200120215830-add-priceHistory-table.js new file mode 100644 index 0000000..eb8f616 --- /dev/null +++ b/app/migrations/20200120215830-add-priceHistory-table.js @@ -0,0 +1,38 @@ +"use strict"; + +module.exports = { + up: (queryInterface, Sequelize) => { + const tableFields = { + id: { + type: Sequelize.BIGINT, + autoIncrement: true, + allowNull: false, + primaryKey: true + }, + realEstateId: { + type: Sequelize.BIGINT, + allowNull: false, + references: { + model: "RealEstate", + key: "id" + }, + onUpdate: "CASCADE", + onDelete: "SET NULL" + }, + price: Sequelize.REAL, + createdAt: { + type: Sequelize.DATE, + defaultValue: Sequelize.literal("NOW()") + }, + updatedAt: { + type: Sequelize.DATE, + defaultValue: Sequelize.literal("NOW()") + } + }; + return queryInterface.createTable("PriceHistory", tableFields); + }, + + down: queryInterface => { + return queryInterface.dropTable("PriceHistory", {}); + } +}; diff --git a/app/models/priceHistory.js b/app/models/priceHistory.js new file mode 100644 index 0000000..ea9ddea --- /dev/null +++ b/app/models/priceHistory.js @@ -0,0 +1,35 @@ +"use strict"; + +module.exports = (sequalize, DataTypes) => { + const PriceHistory = sequalize.define("PriceHistory", { + id: { + type: DataTypes.BIGINT, + autoIncrement: true, + primaryKey: true, + allowNull: false + }, + realEstateId: { + type: DataTypes.BIGINT, + allowNull: false, + + references: { + model: "RealEstate", + key: "id" + }, + onUpdate: "CASCADE", + onDelete: "SET NULL" + }, + price: DataTypes.REAL + }); + + PriceHistory.associate = models => { + PriceHistory.hasMany(models.RealEstate, { + foreignKey: "id", + sourceKey: "realEstateId", + targetKey: "id", + as: "realEstates" + }); + }; + + return PriceHistory; +}; From 42eddb3aa5e6899da304be787b21dae9b38881f0 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 21 Jan 2020 01:19:35 +0100 Subject: [PATCH 07/15] WIP Bulk create not working. --- app/crawler/savers/postgres.js | 13 ++++++++++++- app/helpers/db/priceHistory.js | 19 +++++++++++++++++++ app/helpers/db/realEstate.js | 4 +++- ... 20200121000524-add-priceHistory-table.js} | 8 ++++++-- app/models/priceHistory.js | 9 ++++++--- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 app/helpers/db/priceHistory.js rename app/migrations/{20200120215830-add-priceHistory-table.js => 20200121000524-add-priceHistory-table.js} (83%) diff --git a/app/crawler/savers/postgres.js b/app/crawler/savers/postgres.js index 344e4ac..8c1553f 100644 --- a/app/crawler/savers/postgres.js +++ b/app/crawler/savers/postgres.js @@ -1,6 +1,7 @@ const moment = require("moment"); const { bulkUpsertRealEstates } = require("../../helpers/db/realEstate"); +const { bulkUpsertPriceHistory } = require("../../helpers/db/priceHistory"); class PostgresSaver { connect() { @@ -11,7 +12,17 @@ class PostgresSaver { async save(results) { const savedRecords = await bulkUpsertRealEstates(results); - + //Extruding data for price history table + const resultPrices = savedRecords.map(realEstate => { + return { + realEstateId: realEstate.dataValues.id, + price: realEstate.dataValues.price + }; + }); + const savedPrices = await bulkUpsertPriceHistory(resultPrices); + // + console.log("savedPrices", savedPrices); + // if (Array.isArray(savedRecords)) { const newRealEstates = []; const existingRealEstates = []; diff --git a/app/helpers/db/priceHistory.js b/app/helpers/db/priceHistory.js new file mode 100644 index 0000000..9d62be8 --- /dev/null +++ b/app/helpers/db/priceHistory.js @@ -0,0 +1,19 @@ +"use strict"; +const db = require("../../models/index"); +const sequelize = require("sequelize"); + +const bulkUpsertPriceHistory = async priceHistoryData => { + try { + const order = [["realEstateId", "desc"]]; + + return await db.PriceHistory.bulkCreate(priceHistoryData, { + order + }); + } catch (e) { + console.log("Error bulk upserting priceHistory : ", e); + } +}; + +module.exports = { + bulkUpsertPriceHistory +}; diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index ebeb84c..cb7a2ef 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -63,7 +63,9 @@ const bulkUpsertRealEstates = async realEstateData => { "numberOfViewsAgency" ]; const order = [["updatedAt", "desc"]]; - + // + //console.log("realEstateData:", realEstateData); + // return await db.RealEstate.bulkCreate(realEstateData, { updateOnDuplicate: fieldsToUpdateIfDuplicate, returning: true, diff --git a/app/migrations/20200120215830-add-priceHistory-table.js b/app/migrations/20200121000524-add-priceHistory-table.js similarity index 83% rename from app/migrations/20200120215830-add-priceHistory-table.js rename to app/migrations/20200121000524-add-priceHistory-table.js index eb8f616..6d56f99 100644 --- a/app/migrations/20200120215830-add-priceHistory-table.js +++ b/app/migrations/20200121000524-add-priceHistory-table.js @@ -12,14 +12,18 @@ module.exports = { realEstateId: { type: Sequelize.BIGINT, allowNull: false, + unique: "uniquePriceRealEstate", references: { - model: "RealEstate", + model: "RealEstates", key: "id" }, onUpdate: "CASCADE", onDelete: "SET NULL" }, - price: Sequelize.REAL, + price: { + type: Sequelize.REAL, + unique: "uniquePriceRealEstate" + }, createdAt: { type: Sequelize.DATE, defaultValue: Sequelize.literal("NOW()") diff --git a/app/models/priceHistory.js b/app/models/priceHistory.js index ea9ddea..560a4fa 100644 --- a/app/models/priceHistory.js +++ b/app/models/priceHistory.js @@ -11,15 +11,18 @@ module.exports = (sequalize, DataTypes) => { realEstateId: { type: DataTypes.BIGINT, allowNull: false, - + unique: "uniquePriceRealEstate", references: { - model: "RealEstate", + model: "RealEstates", key: "id" }, onUpdate: "CASCADE", onDelete: "SET NULL" }, - price: DataTypes.REAL + price: { + type: DataTypes.REAL, + unique: "uniquePriceRealEstate" + } }); PriceHistory.associate = models => { From 8d3f001678d29d8a69aa5baf91551e8c8f8ec32d Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 21 Jan 2020 16:28:47 +0100 Subject: [PATCH 08/15] WIP Added model, migration and bulk upsert fnc. --- app/crawler/savers/postgres.js | 9 +++- app/helpers/db/priceHistory.js | 3 +- ...00121094500-add-constraint-priceHistory.js | 10 ++++ app/models/priceHistory.js | 46 +++++++++++-------- .../20200121150443-initial-price-history.js | 19 ++++++++ 5 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 app/migrations/20200121094500-add-constraint-priceHistory.js create mode 100644 app/seeders/20200121150443-initial-price-history.js diff --git a/app/crawler/savers/postgres.js b/app/crawler/savers/postgres.js index 8c1553f..8e31f9d 100644 --- a/app/crawler/savers/postgres.js +++ b/app/crawler/savers/postgres.js @@ -14,9 +14,16 @@ class PostgresSaver { const savedRecords = await bulkUpsertRealEstates(results); //Extruding data for price history table const resultPrices = savedRecords.map(realEstate => { + //Null values canot be recognized by ignore duplicates in sequalize + //Value price = 0 indicates 'cijena na upit' + const priceTmp = + realEstate.dataValues.price === null ? 0 : realEstate.dataValues.price; + return { realEstateId: realEstate.dataValues.id, - price: realEstate.dataValues.price + price: priceTmp, + createdAt: realEstate.dataValues.createdAt, + updatedAt: realEstate.dataValues.updatedAt }; }); const savedPrices = await bulkUpsertPriceHistory(resultPrices); diff --git a/app/helpers/db/priceHistory.js b/app/helpers/db/priceHistory.js index 9d62be8..3e8f69e 100644 --- a/app/helpers/db/priceHistory.js +++ b/app/helpers/db/priceHistory.js @@ -7,7 +7,8 @@ const bulkUpsertPriceHistory = async priceHistoryData => { const order = [["realEstateId", "desc"]]; return await db.PriceHistory.bulkCreate(priceHistoryData, { - order + order, + ignoreDuplicates: true }); } catch (e) { console.log("Error bulk upserting priceHistory : ", e); diff --git a/app/migrations/20200121094500-add-constraint-priceHistory.js b/app/migrations/20200121094500-add-constraint-priceHistory.js new file mode 100644 index 0000000..45c83c3 --- /dev/null +++ b/app/migrations/20200121094500-add-constraint-priceHistory.js @@ -0,0 +1,10 @@ +"use strict"; +module.exports = { + up: (queryInterface, Sequelize) => + queryInterface.addConstraint("PriceHistory", ["realEstateId", "price"], { + type: "unique", + name: "uniquePriceRealEstate" + }), + down: queryInterface => + queryInterface.removeConstraint("PriceHistory", "uniquePriceRealEstate") +}; diff --git a/app/models/priceHistory.js b/app/models/priceHistory.js index 560a4fa..495be53 100644 --- a/app/models/priceHistory.js +++ b/app/models/priceHistory.js @@ -1,29 +1,35 @@ "use strict"; module.exports = (sequalize, DataTypes) => { - const PriceHistory = sequalize.define("PriceHistory", { - id: { - type: DataTypes.BIGINT, - autoIncrement: true, - primaryKey: true, - allowNull: false - }, - realEstateId: { - type: DataTypes.BIGINT, - allowNull: false, - unique: "uniquePriceRealEstate", - references: { - model: "RealEstates", - key: "id" + const PriceHistory = sequalize.define( + "PriceHistory", + { + id: { + type: DataTypes.BIGINT, + autoIncrement: true, + primaryKey: true, + allowNull: false }, - onUpdate: "CASCADE", - onDelete: "SET NULL" + realEstateId: { + type: DataTypes.BIGINT, + allowNull: false, + unique: "uniquePriceRealEstate", + references: { + model: "RealEstates", + key: "id" + }, + onUpdate: "CASCADE", + onDelete: "SET NULL" + }, + price: { + type: DataTypes.REAL, + unique: "uniquePriceRealEstate" + } }, - price: { - type: DataTypes.REAL, - unique: "uniquePriceRealEstate" + { + freezeTableName: true } - }); + ); PriceHistory.associate = models => { PriceHistory.hasMany(models.RealEstate, { diff --git a/app/seeders/20200121150443-initial-price-history.js b/app/seeders/20200121150443-initial-price-history.js new file mode 100644 index 0000000..9d2f5b0 --- /dev/null +++ b/app/seeders/20200121150443-initial-price-history.js @@ -0,0 +1,19 @@ +"use strict"; + +module.exports = { + up: (queryInterface, Sequelize) => { + // ?? + const realEstateInitialData = await queryInterface.Sequelize.findall (); + const priceHistoryInitialData = realEstateInitialData.map (); + + return queryInterface.bulkInsert( + "PriceHistory", + priceHistoryInitialData, + {} + ); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.bulkDelete("PriceHistory", null, {}); + } +}; From c6f0e039a58105c9f8538df18fdd0f4bcd443102 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 21 Jan 2020 23:12:04 +0100 Subject: [PATCH 09/15] Added price history log. --- app/crawler/savers/postgres.js | 4 +-- app/helpers/db/realEstate.js | 4 +-- .../20200121150443-initial-price-history.js | 27 ++++++++++++++----- package.json | 1 + 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/crawler/savers/postgres.js b/app/crawler/savers/postgres.js index 8e31f9d..97ba285 100644 --- a/app/crawler/savers/postgres.js +++ b/app/crawler/savers/postgres.js @@ -27,9 +27,7 @@ class PostgresSaver { }; }); const savedPrices = await bulkUpsertPriceHistory(resultPrices); - // - console.log("savedPrices", savedPrices); - // + if (Array.isArray(savedRecords)) { const newRealEstates = []; const existingRealEstates = []; diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js index cb7a2ef..ebeb84c 100644 --- a/app/helpers/db/realEstate.js +++ b/app/helpers/db/realEstate.js @@ -63,9 +63,7 @@ const bulkUpsertRealEstates = async realEstateData => { "numberOfViewsAgency" ]; const order = [["updatedAt", "desc"]]; - // - //console.log("realEstateData:", realEstateData); - // + return await db.RealEstate.bulkCreate(realEstateData, { updateOnDuplicate: fieldsToUpdateIfDuplicate, returning: true, diff --git a/app/seeders/20200121150443-initial-price-history.js b/app/seeders/20200121150443-initial-price-history.js index 9d2f5b0..0a9531a 100644 --- a/app/seeders/20200121150443-initial-price-history.js +++ b/app/seeders/20200121150443-initial-price-history.js @@ -1,11 +1,26 @@ "use strict"; +const { RealEstate } = require("../models"); + module.exports = { - up: (queryInterface, Sequelize) => { - // ?? - const realEstateInitialData = await queryInterface.Sequelize.findall (); - const priceHistoryInitialData = realEstateInitialData.map (); - + async up(queryInterface, Sequelize) { + //Reading initial data from RealEstate table in db + const realEstateInitialData = await RealEstate.findAll(); + //Extruding data for table PriceHistory + const priceHistoryInitialData = realEstateInitialData.map(realEstate => { + //Null values canot be recognized by ignore duplicates in sequalize + //Value price = 0 indicates 'cijena na upit' + const priceTmp = + realEstate.dataValues.price === null ? 0 : realEstate.dataValues.price; + + return { + realEstateId: realEstate.dataValues.id, + price: priceTmp, + createdAt: realEstate.dataValues.createdAt, + updatedAt: realEstate.dataValues.updatedAt + }; + }); + return queryInterface.bulkInsert( "PriceHistory", priceHistoryInitialData, @@ -13,7 +28,7 @@ module.exports = { ); }, - down: (queryInterface, Sequelize) => { + async down(queryInterface, Sequelize) { return queryInterface.bulkDelete("PriceHistory", null, {}); } }; diff --git a/package.json b/package.json index 75a7cc4..cdb2c5c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "start": "node ./index.js", "start-mon": "nodemon ./index.js", "migrate": "cd app && npx sequelize db:migrate", + "seed": "cd app && npx sequelize db:seed:all", "setup": "docker build -t marketalerts . && docker run -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=marketalerts --name pg_marketalerts -d -p 5432:5432 marketalerts && sleep 10 && npm run migrate", "docker-start": "docker start pg_marketalerts", "docker-stop": "docker stop pg_marketalerts", From 5b3491fdba0e3551dea0bbab3e7c55125b5ee0c9 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 23 Jan 2020 10:12:56 +0100 Subject: [PATCH 10/15] 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 @@ +
+

+ +


From 98263364c723ff3a5ee8f02179c490982a7ad74c Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 23 Jan 2020 11:13:53 +0100 Subject: [PATCH 11/15] 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 = {}; From b2c102bc1ad7eb6ec5d5f856234ee9871493949f Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Thu, 23 Jan 2020 15:48:48 +0100 Subject: [PATCH 12/15] Added check up email that everything works. --- app/helpers/db/searchRequestMatch.js | 13 ++++++++- app/helpers/emailContentGenerator.js | 41 +++++++++++++++++++++++++++- app/npmScripts/npmCheckUpNotify.js | 6 ++++ app/services/notificationService.js | 28 +++++++++++++++++-- package.json | 1 + 5 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 app/npmScripts/npmCheckUpNotify.js diff --git a/app/helpers/db/searchRequestMatch.js b/app/helpers/db/searchRequestMatch.js index 11d5cde..9170863 100644 --- a/app/helpers/db/searchRequestMatch.js +++ b/app/helpers/db/searchRequestMatch.js @@ -40,6 +40,16 @@ const findNotNotifiedMatches = async () => { return matchingRecords; }; +const findAllRequestsForCheckUp = async () => { + const query = { + subscribed: true + }; + const allRequestsForCheckUp = await db.SearchRequest.findAll({ + where: query + }); + + return allRequestsForCheckUp; +}; const addMatches = async matchingRecords => { return await db.SearchRequestMatch.bulkCreate(matchingRecords, { @@ -50,5 +60,6 @@ const addMatches = async matchingRecords => { module.exports = { findRealEstatesForSearchRequest, addMatches, - findNotNotifiedMatches + findNotNotifiedMatches, + findAllRequestsForCheckUp }; diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index 861bfb2..ee30ee6 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -120,8 +120,47 @@ const generateEmailSubject = (numberOfRealEstates, singleRealEstateTitle) => { return `Kivi: ${numberOfRealEstates} novih nekretnina`; }; +const generateCheckUpEmail = searchRequest => { + const realEstateType = AD_CATEGORY[searchRequest.realEstateType]; + const { + id, + gardenSizeMin, + gardenSizeMax, + sizeMin, + sizeMax, + priceMin, + priceMax + } = searchRequest; + + const gardenSize = realEstateType.hasGardenSize + ? `
Kvadratura okućnice: Od ${gardenSizeMin} do ${gardenSizeMax} m2
` + : ``; + + const allRealEstatesLink = `${APP_URL}/nekretnine/${id}`; + const moreRealEstates = `
Kompletan spisak do sada pronađenih nekretnina možete pogledati na listi nekretnina
`; + + const emailFooter = generateEmailFooter(id); + + return `

Zdravo

+
Kivi tim traži nekretnine za Vas i kada to ne vidite.
+
+
Vaša trenutno aktivna pretraga je:
+
+
+
Tip nekretnine: ${realEstateType.title}
+
Kvadratura nekretnine: Od ${sizeMin} do ${sizeMax} m2
+ ${gardenSize} +
Cijena: ${priceMin} do ${priceMax} KM
+
+
+ ${moreRealEstates} +
+ ${emailFooter}`; +}; + module.exports = { generateNotificationEmail, generateNewSearchRequestEmail, - generateEmailSubject + generateEmailSubject, + generateCheckUpEmail }; diff --git a/app/npmScripts/npmCheckUpNotify.js b/app/npmScripts/npmCheckUpNotify.js new file mode 100644 index 0000000..1becb3f --- /dev/null +++ b/app/npmScripts/npmCheckUpNotify.js @@ -0,0 +1,6 @@ +"use strict"; +const { checkUpNotifyAll } = require("../services/notificationService"); + +(async () => { + await checkUpNotifyAll(); +})(); diff --git a/app/services/notificationService.js b/app/services/notificationService.js index 7495e17..10a74df 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -6,9 +6,13 @@ const { const { generateNotificationEmail, generateNewSearchRequestEmail, - generateEmailSubject + generateEmailSubject, + generateCheckUpEmail } = require("../helpers/emailContentGenerator"); -const { findNotNotifiedMatches } = require("../helpers/db/searchRequestMatch"); +const { + findNotNotifiedMatches, + findAllRequestsForCheckUp +} = require("../helpers/db/searchRequestMatch"); const { sendEmail } = require("../services/emailService"); const notifyForNewRealEstates = async newRealEstates => { @@ -109,8 +113,26 @@ const notifyRequestsWithDailyOption = async () => { await notifyMatches(matches, true); }; +const checkUpNotifyAll = async () => { + const searchRequestsForCheckUp = await findAllRequestsForCheckUp(); + + const asyncSendEmailActions = []; + + for (const searchRequest of searchRequestsForCheckUp) { + const { email } = searchRequest.dataValues; + const emailSubject = `Kivi: Mi tražimo nekretnine za vas!`; + const emailContent = generateCheckUpEmail(searchRequest.dataValues); + + const sendEmailPromise = sendEmail(email, emailSubject, emailContent); + asyncSendEmailActions.push(sendEmailPromise); + sendEmailPromise.catch(err => console.log("[Email Sending Failed]", err)); + } + await Promise.all(asyncSendEmailActions); +}; + module.exports = { notifyForNewRealEstates, notifyForNewSearchRequest, - notifyRequestsWithDailyOption + notifyRequestsWithDailyOption, + checkUpNotifyAll }; diff --git a/package.json b/package.json index 75a7cc4..b4ce4a8 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "docker-stop": "docker stop pg_marketalerts", "crawl": "cd app/crawler && node npmCrawl.js", "daily-notify": "cd app/npmScripts && node npmDailyNotify.js", + "checkup-notify": "cd app/npmScripts && node npmCheckUpNotify.js", "test-search": "cd test && node searchTest.js", "test-olx-scraper": "cd test && node olxScrapeTest.js", "test-rental-scraper": "cd test && node rentalScrapeTest.js" From 40509d2836f346bed74a1678f922eb8d55b9c354 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 24 Jan 2020 01:01:10 +0100 Subject: [PATCH 13/15] Changed logic for checkup.For testing. --- app/config/appConfig.js | 5 ++++- app/helpers/db/searchRequestMatch.js | 22 +++++++++++++++++++++- app/npmScripts/npmCheckUpNotify.js | 6 +++--- app/services/notificationService.js | 4 ++-- development.env | 1 + index.js | 7 ++++++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/config/appConfig.js b/app/config/appConfig.js index 7a7887b..d269e6f 100644 --- a/app/config/appConfig.js +++ b/app/config/appConfig.js @@ -14,6 +14,8 @@ const DEFAULT_TIMEZONE = "Europe/Sarajevo"; const CRAWLER_INTERVAL = parseInt(process.env.CRAWLER_INTERVAL) || 60; const STOP_CRAWLER = !!parseInt(process.env.STOP_CRAWLER); +const CHECK_UP_DAYS = parseInt(process.env.CHECK_UP_DAYS) || 10; + const AWS_EMAIL_CONFIG = { REGION: process.env.AWS_REGION || "", CREDENTIALS: { @@ -42,5 +44,6 @@ module.exports = { MAX_REAL_ESTATES_IN_EMAIL, MAX_REAL_ESTATES_IN_FIRST_EMAIL, PRINT_CRAWLER_DEBUG, - API_MAP_KEY + API_MAP_KEY, + CHECK_UP_DAYS }; diff --git a/app/helpers/db/searchRequestMatch.js b/app/helpers/db/searchRequestMatch.js index 9170863..6dfa986 100644 --- a/app/helpers/db/searchRequestMatch.js +++ b/app/helpers/db/searchRequestMatch.js @@ -1,5 +1,6 @@ "use strict"; const db = require("../../models/index"); +const { CHECK_UP_DAYS } = require("../../config/appConfig"); const findRealEstatesForSearchRequest = async searchRequestId => { const query = { @@ -41,8 +42,27 @@ const findNotNotifiedMatches = async () => { return matchingRecords; }; const findAllRequestsForCheckUp = async () => { + //First we find IDs of search request that don't need to be emailed for check up - to EXCLUDE + //The ones that received notification for real estate CHECK_UP_DAYS days from now + const date = new Date(); + const checkUpDate = date.getDate() - CHECK_UP_DAYS; + date.setDate(checkUpDate); + const dateQuery = { + createdAt: { + [Op.gte]: date + } + }; + + const excludedRequests = await db.SearchRequestMatch.findAll({ + attributes: ["searchRequestId"], + where: dateQuery + }); + const query = { - subscribed: true + subscribed: true, + id: { + [Op.notIn]: excludedRequests + } }; const allRequestsForCheckUp = await db.SearchRequest.findAll({ where: query diff --git a/app/npmScripts/npmCheckUpNotify.js b/app/npmScripts/npmCheckUpNotify.js index 1becb3f..b69cbf6 100644 --- a/app/npmScripts/npmCheckUpNotify.js +++ b/app/npmScripts/npmCheckUpNotify.js @@ -1,6 +1,6 @@ "use strict"; -const { checkUpNotifyAll } = require("../services/notificationService"); - +const { checkUpNotify } = require("../services/notificationService"); +//For testing pursposes (async () => { - await checkUpNotifyAll(); + await checkUpNotify(); })(); diff --git a/app/services/notificationService.js b/app/services/notificationService.js index 10a74df..d0f382e 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -113,7 +113,7 @@ const notifyRequestsWithDailyOption = async () => { await notifyMatches(matches, true); }; -const checkUpNotifyAll = async () => { +const checkUpNotify = async () => { const searchRequestsForCheckUp = await findAllRequestsForCheckUp(); const asyncSendEmailActions = []; @@ -134,5 +134,5 @@ module.exports = { notifyForNewRealEstates, notifyForNewSearchRequest, notifyRequestsWithDailyOption, - checkUpNotifyAll + checkUpNotify }; diff --git a/development.env b/development.env index 89f0a1e..f8f3d52 100644 --- a/development.env +++ b/development.env @@ -11,6 +11,7 @@ APP_BASE_URL=base url for the app MAX_REAL_ESTATES_IN_EMAIL=Max number of real estates that will be shown in email, others will be truncated and URL with full list will be shwon MAX_REAL_ESTATES_IN_FIRST_EMAIL=Max number of real estates that will be shown in first (welcome) email +CHECK_UP_DAYS=Check up email is sent after this number of days without notification #=============== GOOGLE ANALYTICS =============# GA_ID=Google Analytics ID diff --git a/index.js b/index.js index 074099b..abcd14b 100644 --- a/index.js +++ b/index.js @@ -8,10 +8,12 @@ const forceSSL = require("./app/helpers/forceSSL"); const { APP_PORT, CRAWLER_INTERVAL, - STOP_CRAWLER + STOP_CRAWLER, + CHECK_UP_DAYS } = require("./app/config/appConfig"); const routes = require("./app/routes"); const { crawlAll } = require("./app/crawler/crawl"); +const { checkUpNotify } = require("./app/services/notificationService"); const { notifyForNewRealEstates } = require("./app/services/notificationService"); @@ -45,4 +47,7 @@ const crawl = () => { }); } }; + setInterval(crawl, CRAWLER_INTERVAL * 1000); + +setInterval(checkUpNotify, CHECK_UP_DAYS * 24 * 60 * 60 * 1000); From 470f53d29b85a81c1c38f6877a75e2c1ee6602da Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Fri, 24 Jan 2020 16:04:28 +0100 Subject: [PATCH 14/15] Changed to send email only to some users. --- app/helpers/db/searchRequestMatch.js | 13 +++++++++++-- app/helpers/emailContentGenerator.js | 5 ----- index.js | 5 ++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/helpers/db/searchRequestMatch.js b/app/helpers/db/searchRequestMatch.js index 6dfa986..794711b 100644 --- a/app/helpers/db/searchRequestMatch.js +++ b/app/helpers/db/searchRequestMatch.js @@ -1,5 +1,7 @@ "use strict"; const db = require("../../models/index"); +const sequelize = require("sequelize"); +const Op = sequelize.Op; const { CHECK_UP_DAYS } = require("../../config/appConfig"); const findRealEstatesForSearchRequest = async searchRequestId => { @@ -53,11 +55,18 @@ const findAllRequestsForCheckUp = async () => { } }; - const excludedRequests = await db.SearchRequestMatch.findAll({ + const excludedMatches = await db.SearchRequestMatch.findAll({ attributes: ["searchRequestId"], - where: dateQuery + where: dateQuery, + order: [["searchRequestId", "ASC"]] }); + const excludedRequestsAll = excludedMatches.map(match => { + return match.dataValues.searchRequestId; + }); + //Removing duplicate search request id-s for optimization + const excludedRequests = [...new Set(excludedRequestsAll)]; + const query = { subscribed: true, id: { diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index ee30ee6..4bd2c59 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -136,9 +136,6 @@ const generateCheckUpEmail = searchRequest => { ? `
Kvadratura okućnice: Od ${gardenSizeMin} do ${gardenSizeMax} m2
` : ``; - const allRealEstatesLink = `${APP_URL}/nekretnine/${id}`; - const moreRealEstates = `
Kompletan spisak do sada pronađenih nekretnina možete pogledati na listi nekretnina
`; - const emailFooter = generateEmailFooter(id); return `

Zdravo

@@ -153,8 +150,6 @@ const generateCheckUpEmail = searchRequest => {
Cijena: ${priceMin} do ${priceMax} KM

- ${moreRealEstates} -
${emailFooter}`; }; diff --git a/index.js b/index.js index abcd14b..0669e7b 100644 --- a/index.js +++ b/index.js @@ -8,8 +8,7 @@ const forceSSL = require("./app/helpers/forceSSL"); const { APP_PORT, CRAWLER_INTERVAL, - STOP_CRAWLER, - CHECK_UP_DAYS + STOP_CRAWLER } = require("./app/config/appConfig"); const routes = require("./app/routes"); const { crawlAll } = require("./app/crawler/crawl"); @@ -50,4 +49,4 @@ const crawl = () => { setInterval(crawl, CRAWLER_INTERVAL * 1000); -setInterval(checkUpNotify, CHECK_UP_DAYS * 24 * 60 * 60 * 1000); +setInterval(checkUpNotify, 1000 * 60 * 60 * 24); From fa46f75dd329b501afac0a75efc935900250626c Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Tue, 28 Jan 2020 22:28:52 +0100 Subject: [PATCH 15/15] 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 @@