Changed acces road type check and include incomplete
This commit is contained in:
@@ -120,6 +120,7 @@ const getFilters = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const postFilters = async (req, res) => {
|
const postFilters = async (req, res) => {
|
||||||
|
|
||||||
const searchRequest = await currentSearchRequest(req);
|
const searchRequest = await currentSearchRequest(req);
|
||||||
|
|
||||||
if (!searchRequest || !searchRequest.dataValues) {
|
if (!searchRequest || !searchRequest.dataValues) {
|
||||||
@@ -232,7 +233,6 @@ const postFilters = async (req, res) => {
|
|||||||
searchRequest.gardenSizeMin = gardenSizeMin;
|
searchRequest.gardenSizeMin = gardenSizeMin;
|
||||||
searchRequest.gardenSizeMax = gardenSizeMax;
|
searchRequest.gardenSizeMax = gardenSizeMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
await searchRequest.save();
|
await searchRequest.save();
|
||||||
|
|
||||||
res.redirect(nextStepUrl);
|
res.redirect(nextStepUrl);
|
||||||
|
|||||||
@@ -130,8 +130,11 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const geoSearchQueryPart = sequelize.where(contains, true);
|
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 = {
|
const query = {
|
||||||
adType,
|
adType,
|
||||||
@@ -148,33 +151,134 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
|||||||
//
|
//
|
||||||
gardenSize: {
|
gardenSize: {
|
||||||
[Op.lte]: gardenSizeMax,
|
[Op.lte]: gardenSizeMax,
|
||||||
[Op.gte]: gardenSizeMin,
|
[Op.gte]: gardenSizeMin
|
||||||
},
|
},
|
||||||
numberOfRooms: {
|
numberOfRooms: {
|
||||||
[Op.lte]: numberOfRoomsMax,
|
[Op.lte]: numberOfRoomsMax,
|
||||||
[Op.gte]: numberOfRoomsMin,
|
[Op.gte]: numberOfRoomsMin
|
||||||
},
|
},
|
||||||
numberOfFloors: {
|
numberOfFloors: {
|
||||||
[Op.lte]: numberOfFloorsMax,
|
[Op.lte]: numberOfFloorsMax,
|
||||||
[Op.gte]: numberOfFloorsMin,
|
[Op.gte]: numberOfFloorsMin
|
||||||
},
|
},
|
||||||
floor: {
|
floor: {
|
||||||
[Op.lte]: floorMax,
|
[Op.lte]: floorMax,
|
||||||
[Op.gte]: floorMin,
|
[Op.gte]: floorMin
|
||||||
|
},
|
||||||
|
accessRoadType: {
|
||||||
|
[Op.or]: {
|
||||||
|
[Op.eq]: 'ANY',
|
||||||
|
[Op.eq]: accessRoadType
|
||||||
|
}
|
||||||
},
|
},
|
||||||
accessRoadType,
|
|
||||||
balcony,
|
balcony,
|
||||||
newBuilding,
|
newBuilding,
|
||||||
elevator
|
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"]];
|
const order = [["updatedAt", "desc"]];
|
||||||
|
|
||||||
return await db.RealEstate.findAll({
|
if(!includeIncompleteAds) {
|
||||||
where: query,
|
return await db.RealEstate.findAll({
|
||||||
limit: maxResults,
|
where: query,
|
||||||
order
|
limit: maxResults,
|
||||||
});
|
order
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return await db.RealEstate.findAll({
|
||||||
|
where: queryIncludeIncomplete,
|
||||||
|
limit: maxResults,
|
||||||
|
order
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const Op = sequelize.Op;
|
|||||||
|
|
||||||
const getSearchRequest = async searchRequestId => {
|
const getSearchRequest = async searchRequestId => {
|
||||||
try {
|
try {
|
||||||
console.log("test");
|
|
||||||
return await db.SearchRequest.findByPk(searchRequestId);
|
return await db.SearchRequest.findByPk(searchRequestId);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -51,12 +51,13 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
|||||||
|
|
||||||
const geoSearchQueryPart = sequelize.where(contains, true);
|
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 = {
|
const query = {
|
||||||
adType,
|
adType,
|
||||||
realEstateType,
|
realEstateType,
|
||||||
subscribed: true,
|
subscribed: true,
|
||||||
//
|
//
|
||||||
accessRoadType,
|
|
||||||
balcony,
|
balcony,
|
||||||
newBuilding,
|
newBuilding,
|
||||||
elevator,
|
elevator,
|
||||||
@@ -113,6 +114,14 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
|||||||
[Op.gte]: floor
|
[Op.gte]: floor
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (accessRoadType) {
|
||||||
|
query.accessRoadType = {
|
||||||
|
[Op.or]: {
|
||||||
|
[Op.eq]: 'ANY',
|
||||||
|
[Op.eq]: accessRoadType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return await db.SearchRequest.findAll({ where: query });
|
return await db.SearchRequest.findAll({ where: query });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user