Changed searchRequest to include case of incomplete ads wanted.

This commit is contained in:
Naida Vatric
2019-12-18 02:04:31 +01:00
parent 4391aa5939
commit 251437f815
2 changed files with 85 additions and 3 deletions

View File

@@ -104,6 +104,13 @@ const AD_CATEGORY = {
id: "FLAT",
title: "Stan",
hasGardenSize: false,
hasAccesRoadType: true,
hasBalconyProp: true,
hasNewBuildingProp: true,
hasElevatorProp: true,
hasNumberOfRoom: true,
hasNumberOfFloors: false,
hasFloorProp: true,
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
@@ -112,6 +119,13 @@ const AD_CATEGORY = {
id: "HOUSE",
title: "Kuća",
hasGardenSize: true,
hasAccesRoadType: true,
hasBalconyProp: true,
hasNewBuildingProp: true,
hasElevatorProp: false,
hasNumberOfRoom: true,
hasNumberOfFloors: true,
hasFloorProp: false,
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS,
@@ -121,6 +135,13 @@ const AD_CATEGORY = {
id: "OFFICE",
title: "Kancelarija",
hasGardenSize: false,
hasAccesRoadType: true,
hasBalconyProp: false,
hasNewBuildingProp: true,
hasElevatorProp: true,
hasNumberOfRoom: true,
hasNumberOfFloors: false,
hasFloorProp: true,
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
@@ -129,6 +150,13 @@ const AD_CATEGORY = {
id: "LAND",
title: "Zemljište",
hasGardenSize: false,
hasAccesRoadType: true,
hasBalconyProp: false,
hasNewBuildingProp: false,
hasElevatorProp: false,
hasNumberOfRoom: false,
hasNumberOfFloors: false,
hasFloorProp: false,
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: LAND_SIZE_SLIDER_OPTIONS
@@ -137,6 +165,13 @@ const AD_CATEGORY = {
id: "APARTMENT",
title: "Apartman",
hasGardenSize: false,
hasAccesRoadType: true,
hasBalconyProp: true,
hasNewBuildingProp: true,
hasElevatorProp: true,
hasNumberOfRoom: true,
hasNumberOfFloors: false,
hasFloorProp: true,
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
@@ -145,6 +180,13 @@ const AD_CATEGORY = {
id: "GARAGE",
title: "Garaža",
hasGardenSize: false,
hasAccesRoadType: true,
hasBalconyProp: false,
hasNewBuildingProp: false,
hasElevatorProp: false,
hasNumberOfRoom: false,
hasNumberOfFloors: false,
hasFloorProp: false,
priceSliderOptionsSale: GARAGE_PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: GARAGE_PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: GARAGE_SIZE_SLIDER_OPTIONS
@@ -153,6 +195,13 @@ const AD_CATEGORY = {
id: "COTTAGE",
title: "Vikendica",
hasGardenSize: true,
hasAccesRoadType: true,
hasBalconyProp: true,
hasNewBuildingProp: true,
hasElevatorProp: false,
hasNumberOfRoom: true,
hasNumberOfFloors: true,
hasFloorProp: false,
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS,

View File

@@ -2,6 +2,7 @@
const db = require("../../models/index");
const sequelize = require("sequelize");
const Op = sequelize.Op;
const { AD_CATEGORY } = require("../../common/enums");
const getSearchRequest = async searchRequestId => {
try {
@@ -48,15 +49,20 @@ const findSearchRequestsForRealEstate = async realEstate => {
const geoSearchQueryPart = sequelize.where(contains, true);
//General query contains only attributes that are defined for every realestate - not null
//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
let checkForIncompleteWanted = false;
//Every other attribute is checked separately and included in query only if it is defined
//Attributes are checked separately and included in query only if defined
//Price and area should be defined for every property
if (price) {
query.priceMin = {
[Op.lte]: price
@@ -64,6 +70,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.priceMax = {
[Op.gte]: price
};
} else {
checkForIncompleteWanted = true;
}
if (area) {
@@ -73,8 +81,10 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.sizeMax = {
[Op.gte]: area
};
} else {
checkForIncompleteWanted = true;
}
//Other attributes can be defined or not depending on RealEstate type
if (gardenSize) {
query.gardenSizeMin = {
[Op.lte]: gardenSize
@@ -82,6 +92,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.gardenSizeMax = {
[Op.gte]: gardenSize
};
} else if (realEstateTypeObject.hasGardenSize) {
checkForIncompleteWanted = true;
}
if (numberOfRooms) {
@@ -91,6 +103,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.numberOfRoomsMax = {
[Op.gte]: numberOfRooms
};
} else if (realEstateTypeObject.hasNumberOfRoom) {
checkForIncompleteWanted = true;
}
if (numberOfFloors) {
@@ -100,6 +114,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.numberOfFloorsMax = {
[Op.gte]: numberOfFloors
};
} else if (realEstateTypeObject.hasNumberOfFloors) {
checkForIncompleteWanted = true;
}
if (floor) {
@@ -109,6 +125,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.floorMax = {
[Op.gte]: floor
};
} else if (realEstateTypeObject.hasFloorProp) {
checkForIncompleteWanted = true;
}
if (accessRoadType) {
@@ -118,26 +136,41 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.eq]: accessRoadType
}
};
} else if (realEstateTypeObject.hasAccesRoadType) {
checkForIncompleteWanted = true;
}
if (balcony) {
query.balcony = {
[Op.eq]: balcony
};
} else if (realEstateTypeObject.hasBalconyProp) {
checkForIncompleteWanted = true;
}
if (newBuilding) {
query.newBuilding = {
[Op.eq]: newBuilding
};
} else if (realEstateTypeObject.hasNewBuildingProp) {
checkForIncompleteWanted = true;
}
if (elevator) {
query.elevator = {
[Op.eq]: elevator
};
} else if (realEstateTypeObject.hasElevatorProp) {
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
if (checkForIncompleteWanted) {
query.includeIncompleteAds = {
[Op.eq]: true
};
}
return await db.SearchRequest.findAll({ where: query });
};