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

View File

@@ -2,6 +2,7 @@
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 getSearchRequest = async searchRequestId => { const getSearchRequest = async searchRequestId => {
try { try {
@@ -48,15 +49,20 @@ const findSearchRequestsForRealEstate = async realEstate => {
const geoSearchQueryPart = sequelize.where(contains, true); 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 = { const query = {
adType, adType,
realEstateType, realEstateType,
subscribed: true, subscribed: true,
[Op.and]: geoSearchQueryPart [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) { if (price) {
query.priceMin = { query.priceMin = {
[Op.lte]: price [Op.lte]: price
@@ -64,6 +70,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.priceMax = { query.priceMax = {
[Op.gte]: price [Op.gte]: price
}; };
} else {
checkForIncompleteWanted = true;
} }
if (area) { if (area) {
@@ -73,8 +81,10 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.sizeMax = { query.sizeMax = {
[Op.gte]: area [Op.gte]: area
}; };
} else {
checkForIncompleteWanted = true;
} }
//Other attributes can be defined or not depending on RealEstate type
if (gardenSize) { if (gardenSize) {
query.gardenSizeMin = { query.gardenSizeMin = {
[Op.lte]: gardenSize [Op.lte]: gardenSize
@@ -82,6 +92,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.gardenSizeMax = { query.gardenSizeMax = {
[Op.gte]: gardenSize [Op.gte]: gardenSize
}; };
} else if (realEstateTypeObject.hasGardenSize) {
checkForIncompleteWanted = true;
} }
if (numberOfRooms) { if (numberOfRooms) {
@@ -91,6 +103,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.numberOfRoomsMax = { query.numberOfRoomsMax = {
[Op.gte]: numberOfRooms [Op.gte]: numberOfRooms
}; };
} else if (realEstateTypeObject.hasNumberOfRoom) {
checkForIncompleteWanted = true;
} }
if (numberOfFloors) { if (numberOfFloors) {
@@ -100,6 +114,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.numberOfFloorsMax = { query.numberOfFloorsMax = {
[Op.gte]: numberOfFloors [Op.gte]: numberOfFloors
}; };
} else if (realEstateTypeObject.hasNumberOfFloors) {
checkForIncompleteWanted = true;
} }
if (floor) { if (floor) {
@@ -109,6 +125,8 @@ const findSearchRequestsForRealEstate = async realEstate => {
query.floorMax = { query.floorMax = {
[Op.gte]: floor [Op.gte]: floor
}; };
} else if (realEstateTypeObject.hasFloorProp) {
checkForIncompleteWanted = true;
} }
if (accessRoadType) { if (accessRoadType) {
@@ -118,26 +136,41 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.eq]: accessRoadType [Op.eq]: accessRoadType
} }
}; };
} else if (realEstateTypeObject.hasAccesRoadType) {
checkForIncompleteWanted = true;
} }
if (balcony) { if (balcony) {
query.balcony = { query.balcony = {
[Op.eq]: balcony [Op.eq]: balcony
}; };
} else if (realEstateTypeObject.hasBalconyProp) {
checkForIncompleteWanted = true;
} }
if (newBuilding) { if (newBuilding) {
query.newBuilding = { query.newBuilding = {
[Op.eq]: newBuilding [Op.eq]: newBuilding
}; };
} else if (realEstateTypeObject.hasNewBuildingProp) {
checkForIncompleteWanted = true;
} }
if (elevator) { if (elevator) {
query.elevator = { query.elevator = {
[Op.eq]: 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 }); return await db.SearchRequest.findAll({ where: query });
}; };