Changed acces road type check and include incomplete

This commit is contained in:
Naida Vatric
2019-12-13 00:45:28 +01:00
parent 0e585e74ae
commit e83712fb33
3 changed files with 129 additions and 16 deletions

View File

@@ -120,6 +120,7 @@ const getFilters = async (req, res) => {
};
const postFilters = async (req, res) => {
const searchRequest = await currentSearchRequest(req);
if (!searchRequest || !searchRequest.dataValues) {
@@ -232,7 +233,6 @@ const postFilters = async (req, res) => {
searchRequest.gardenSizeMin = gardenSizeMin;
searchRequest.gardenSizeMax = gardenSizeMax;
}
await searchRequest.save();
res.redirect(nextStepUrl);

View File

@@ -130,9 +130,12 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
);
const geoSearchQueryPart = sequelize.where(contains, true);
//Does not work with incomplete data
//issue https://github.com/sequelize/sequelize/issues/11564
//Query for case of complete ads
//WIP This wont work, need to separate queries by adType and realEstateType
//because for example flat does not have gardenSize and that can't be in query
const query = {
adType,
realEstateType,
@@ -148,33 +151,134 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
//
gardenSize: {
[Op.lte]: gardenSizeMax,
[Op.gte]: gardenSizeMin,
[Op.gte]: gardenSizeMin
},
numberOfRooms: {
[Op.lte]: numberOfRoomsMax,
[Op.gte]: numberOfRoomsMin,
[Op.gte]: numberOfRoomsMin
},
numberOfFloors: {
[Op.lte]: numberOfFloorsMax,
[Op.gte]: numberOfFloorsMin,
[Op.gte]: numberOfFloorsMin
},
floor: {
[Op.lte]: floorMax,
[Op.gte]: floorMin,
[Op.gte]: floorMin
},
accessRoadType: {
[Op.or]: {
[Op.eq]: 'ANY',
[Op.eq]: accessRoadType
}
},
accessRoadType,
balcony,
newBuilding,
elevator
};
//Query for case of incomplete ads
const queryIncludeIncomplete = {
adType,
realEstateType,
price: {
[Op.or] : {
[Op.and] : {
[Op.lte]: priceMax,
[Op.gte]: priceMin
},
[Op.is] : null
}
},
area: {
[Op.or] : {
[Op.and]: {
[Op.lte]: sizeMax,
[Op.gte]: sizeMin
},
[Op.is]: null
}
},
[Op.and]: geoSearchQueryPart,
//
gardenSize: {
[Op.or] : {
[Op.and]: {
[Op.lte]: gardenSizeMax,
[Op.gte]: gardenSizeMin
},
[Op.is]: null
}
},
numberOfRooms: {
[Op.or]: {
[Op.and]: {
[Op.lte]: numberOfRoomsMax,
[Op.gte]: numberOfRoomsMin
},
[Op.is]: null
}
},
numberOfFloors: {
[Op.or] : {
[Op.and]: {
[Op.lte]: numberOfFloorsMax,
[Op.gte]: numberOfFloorsMin
},
[Op.is]: null
}
},
floor: {
[Op.or] : {
[Op.and]: {
[Op.lte]: floorMax,
[Op.gte]: floorMin
},
[Op.is]: null
}
},
accessRoadType: {
[Op.or]: {
[Op.eq]: 'ANY',
[Op.eq]: accessRoadType,
[Op.is]: null
}
},
balcony: {
[Op.or]: {
[Op.eq]: balcony,
[Op.is]: null
}
},
newBuilding: {
[Op.or]: {
[Op.eq]: newBuilding,
[Op.is]: null
}
},
elevator: {
[Op.or]: {
[Op.eq]: elevator,
[Op.is]: null
}
}
};
const order = [["updatedAt", "desc"]];
return await db.RealEstate.findAll({
where: query,
limit: maxResults,
order
});
if(!includeIncompleteAds) {
return await db.RealEstate.findAll({
where: query,
limit: maxResults,
order
});
} else {
return await db.RealEstate.findAll({
where: queryIncludeIncomplete,
limit: maxResults,
order
});
}
};
module.exports = {

View File

@@ -5,7 +5,7 @@ const Op = sequelize.Op;
const getSearchRequest = async searchRequestId => {
try {
console.log("test");
return await db.SearchRequest.findByPk(searchRequestId);
} catch (error) {
@@ -51,12 +51,13 @@ const findSearchRequestsForRealEstate = async realEstate => {
const geoSearchQueryPart = sequelize.where(contains, true);
//WIP This wont work, need to separate queries by adType and realEstateType
//because for example flat does not have gardenSize and that can't be in query
const query = {
adType,
realEstateType,
subscribed: true,
//
accessRoadType,
balcony,
newBuilding,
elevator,
@@ -113,6 +114,14 @@ const findSearchRequestsForRealEstate = async realEstate => {
[Op.gte]: floor
};
}
if (accessRoadType) {
query.accessRoadType = {
[Op.or]: {
[Op.eq]: 'ANY',
[Op.eq]: accessRoadType
}
}
}
return await db.SearchRequest.findAll({ where: query });
};