diff --git a/.gitignore b/.gitignore index d0441a1..02b0461 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules/ .env .idea/ .eslintrc -.vscode/ \ No newline at end of file +.vscode/ diff --git a/app/controllers/location.js b/app/controllers/location.js index afbf43f..214fcbf 100644 --- a/app/controllers/location.js +++ b/app/controllers/location.js @@ -4,9 +4,37 @@ const getLocation = async (req, res) => { const title = "Odaberite lokaciju"; const nextStep = req.query.nextStep || "/"; + //Check if location data already exists (active request) + //If it does then get location is called through edit field query + //and map should show already selected location not initial map + let selectedLatLngBounds = {}; + let boundsSelected = false; + + const searchRequest = await currentSearchRequest(req); + + if (!searchRequest || !searchRequest.dataValues) { + res.render("notFound", { title: " " }); + return; + } + const selectedArea = searchRequest.areaToSearch; + const sw = selectedArea.coordinates[0][3]; + const ne = selectedArea.coordinates[0][1]; + + if (sw[0] && ne[0]) { + selectedLatLngBounds = { + swLat: sw[1], + swLng: sw[0], + neLat: ne[1], + neLng: ne[0] + }; + boundsSelected = true; + } + res.render("location", { nextStep, - title + title, + boundsSelected, + selectedLatLngBounds }); }; diff --git a/app/crawler/specificCrawlers/rental.js b/app/crawler/specificCrawlers/rental.js index 8f38dc8..39eb1c5 100644 --- a/app/crawler/specificCrawlers/rental.js +++ b/app/crawler/specificCrawlers/rental.js @@ -312,7 +312,7 @@ class RentalCrawler { let numberOfRooms = parseInt(extractedData["re_realEstates_roomsNO"]) + - parseInt(extractedData["re_realEstates_bedroomNO"]) || null, + parseInt(extractedData["re_realEstates_bedNO"]) || null, numberOfFloors = parseInt(extractedData["re_realEstates_floorsNO"]) || this.getNumberOfFloorsFromFloorId(extractedData["re_floorNO_id"]), @@ -352,7 +352,9 @@ class RentalCrawler { realEstatePropertiesFromInfrastructure.phoneConnection, cableTV = realEstatePropertiesFromInfrastructure.cableTV, internet = realEstatePropertiesFromInfrastructure.internet, - basementAttic = realEstatePropertiesFromSpaces.basementAttic, + basementAttic = + realEstatePropertiesFromSpaces.basementAttic || + this.checkBasemAtticFromFloors(extractedData["re_floorNO_id"]), storeRoom = realEstatePropertiesFromSpaces.storeRoom, videoSurveillance = realEstatePropertiesFromDescriptions.videoSurveillance || @@ -397,9 +399,7 @@ class RentalCrawler { ); if (!publishedDateMoment.isValid()) { throw { - message: `Invalid published date : ${ - extractedData["re_realEstates_inserted"] - }` + message: `Invalid published date : ${extractedData["re_realEstates_inserted"]}` }; } @@ -410,9 +410,7 @@ class RentalCrawler { ); if (!renewedDateMoment.isValid()) { throw { - message: `Invalid renewed date : ${ - extractedData["re_realEstates_edited"] - }` + message: `Invalid renewed date : ${extractedData["re_realEstates_edited"]}` }; } @@ -782,8 +780,42 @@ class RentalCrawler { if (floorIds.length === 0) { return null; } + let noOfFloors = floorIds.length; + // Floors of 'suteren', 'podrum', 'tavan' and 'potkrovlje' are not counted + floorIds.forEach(id => { + if ( + parseInt(id) === 1 || + parseInt(id) === 2 || + parseInt(id) === 12 || + parseInt(id) === 14 + ) { + noOfFloors--; + } + }); + return noOfFloors; + } - return floorIds.length; + checkBasemAtticFromFloors(floorsIdText) { + // floorIdText can be array of numbers, separated by comma or number + const floorIds = floorsIdText.split(","); + + let check = false; + + if (floorIds.length === 0) { + check = false; + } + //If floors 'suteren', 'podrum', 'tavan' and 'potkrovlje' exists then tag for basement-attic is true + floorIds.forEach(id => { + if ( + parseInt(id) === 1 || + parseInt(id) === 2 || + parseInt(id) === 12 || + parseInt(id) === 14 + ) { + check = true; + } + }); + return check; } async sleep(ms) { diff --git a/app/views/location.ejs b/app/views/location.ejs index 01a25ef..8e30feb 100644 --- a/app/views/location.ejs +++ b/app/views/location.ejs @@ -1,13 +1,17 @@