Changed accesRoadType logic

This commit is contained in:
Naida Vatric
2019-12-26 23:30:05 +01:00
parent 42ff1f762f
commit d5d3a1f306
2 changed files with 26 additions and 12 deletions

View File

@@ -2,6 +2,8 @@
const db = require("../../models/index"); const db = require("../../models/index");
const sequelize = require("sequelize"); const sequelize = require("sequelize");
const Op = sequelize.Op; const Op = sequelize.Op;
const { AD_CATEGORY } = require("../../common/enums");
const bulkUpsertRealEstates = async realEstateData => { const bulkUpsertRealEstates = async realEstateData => {
try { try {
const fieldsToUpdateIfDuplicate = [ const fieldsToUpdateIfDuplicate = [
@@ -102,6 +104,9 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
accessRoadType accessRoadType
} = searchRequest; } = searchRequest;
//Needed for defining which attribute should exist or not
const realEstateTypeObject = AD_CATEGORY[realEstateType];
const longitudeColumn = sequelize.col("locationLong"); const longitudeColumn = sequelize.col("locationLong");
const latitudeColumn = sequelize.col("locationLat"); const latitudeColumn = sequelize.col("locationLat");
@@ -175,8 +180,13 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
[Op.and]: geoSearchQueryPart [Op.and]: geoSearchQueryPart
}; };
//Every other attribute is checked separately and included in query only if it is defined/not null //Every other attribute is checked separately and included in query only if it is defined for real estate type
if (gardenSizeMax!=null && gardenSizeMin!=null) {
if (
realEstateTypeObject.hasGardenSize &&
gardenSizeMax != null &&
gardenSizeMin != null
) {
query.gardenSize = { query.gardenSize = {
[Op.lte]: gardenSizeMax, [Op.lte]: gardenSizeMax,
[Op.gte]: gardenSizeMin [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 = { query.numberOfRooms = {
[Op.lte]: numberOfRoomsMax, [Op.lte]: numberOfRoomsMax,
[Op.gte]: numberOfRoomsMin [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 = { query.numberOfFloors = {
[Op.lte]: numberOfFloorsMax, [Op.lte]: numberOfFloorsMax,
[Op.gte]: numberOfFloorsMin [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 = { query.floor = {
[Op.lte]: floorMax, [Op.lte]: floorMax,
[Op.gte]: floorMin [Op.gte]: floorMin
@@ -240,7 +250,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (balcony!=null) { if (realEstateTypeObject.hasBalconyProp && balcony != null) {
query.balcony = { query.balcony = {
[Op.eq]: balcony [Op.eq]: balcony
}; };
@@ -252,7 +262,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (newBuilding!=null) { if (realEstateTypeObject.hasNewBuildingProp && newBuilding != null) {
query.newBuilding = { query.newBuilding = {
[Op.eq]: newBuilding [Op.eq]: newBuilding
}; };
@@ -264,7 +274,7 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
}; };
} }
if (elevator!=null) { if (realEstateTypeObject.hasElevatorProp && elevator != null) {
query.elevator = { query.elevator = {
[Op.eq]: 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") { if (accessRoadType !== "ANY") {
query.accessRoadType = { query.accessRoadType = {
[Op.eq]: accessRoadType [Op.eq]: accessRoadType

View File

@@ -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) { if (accessRoadType != null) {
query.accessRoadType = { query.accessRoadType = {
[Op.or]: { [Op.or]: {
@@ -145,8 +145,11 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.eq]: accessRoadType [Op.eq]: accessRoadType
} }
}; };
} else if (realEstateTypeObject.hasAccesRoadType) { } else {
checkForIncompleteWanted = true; //Null values are returned for user request that wanted ANY acces road type
query.accessRoadType = {
[Op.eq]: "ANY"
};
} }
if (realEstateTypeObject.hasBalconyProp) { if (realEstateTypeObject.hasBalconyProp) {