apply prettier
This commit is contained in:
@@ -120,7 +120,6 @@ const getFilters = async (req, res) => {
|
||||
};
|
||||
|
||||
const postFilters = async (req, res) => {
|
||||
|
||||
const searchRequest = await currentSearchRequest(req);
|
||||
|
||||
if (!searchRequest || !searchRequest.dataValues) {
|
||||
|
||||
@@ -131,42 +131,42 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
|
||||
//General queries contain only attributes that are defined for every searchreq
|
||||
|
||||
//Query for case of complete ads
|
||||
//Query for case of complete ads
|
||||
const query = {
|
||||
adType,
|
||||
realEstateType,
|
||||
price: {
|
||||
[Op.lte]: priceMax,
|
||||
[Op.gte]: priceMin
|
||||
},
|
||||
area: {
|
||||
[Op.lte]: sizeMax,
|
||||
[Op.gte]: sizeMin
|
||||
},
|
||||
accessRoadType: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: 'ANY',
|
||||
[Op.eq]: accessRoadType
|
||||
}
|
||||
},
|
||||
[Op.and]: geoSearchQueryPart
|
||||
}
|
||||
|
||||
adType,
|
||||
realEstateType,
|
||||
price: {
|
||||
[Op.lte]: priceMax,
|
||||
[Op.gte]: priceMin
|
||||
},
|
||||
area: {
|
||||
[Op.lte]: sizeMax,
|
||||
[Op.gte]: sizeMin
|
||||
},
|
||||
accessRoadType: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: "ANY",
|
||||
[Op.eq]: accessRoadType
|
||||
}
|
||||
},
|
||||
[Op.and]: geoSearchQueryPart
|
||||
};
|
||||
|
||||
//Query for case of incomplete ads
|
||||
const queryIncludeIncomplete = {
|
||||
adType,
|
||||
realEstateType,
|
||||
price: {
|
||||
[Op.or] : {
|
||||
[Op.and] : {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: priceMax,
|
||||
[Op.gte]: priceMin
|
||||
},
|
||||
[Op.is] : null
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
area: {
|
||||
[Op.or] : {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: sizeMax,
|
||||
[Op.gte]: sizeMin
|
||||
@@ -176,118 +176,118 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
},
|
||||
accessRoadType: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: 'ANY',
|
||||
[Op.eq]: "ANY",
|
||||
[Op.eq]: accessRoadType,
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
[Op.and]: geoSearchQueryPart
|
||||
}
|
||||
};
|
||||
|
||||
//Every other attribute is checked separately and included in query only if it is defined
|
||||
if (gardenSizeMax && gardenSizeMin) {
|
||||
query.gardenSize = {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.gardenSize = {
|
||||
[Op.or] : {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (numberOfRoomsMin && numberOfRoomsMax) {
|
||||
query.numberOfRooms = {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.numberOfRooms = {
|
||||
[Op.or] : {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (numberOfFloorsMin && numberOfFloorsMax) {
|
||||
query.numberOfFloors = {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.numberOfFloors = {
|
||||
[Op.or] : {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (floorMin && floorMax) {
|
||||
query.floor = {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.floor = {
|
||||
[Op.or] : {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (balcony) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.balcony = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: balcony,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (newBuilding) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.newBuilding = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: newBuilding,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (elevator) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
}
|
||||
};
|
||||
queryIncludeIncomplete.elevator = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: elevator,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const order = [["updatedAt", "desc"]];
|
||||
|
||||
if(!includeIncompleteAds) {
|
||||
if (!includeIncompleteAds) {
|
||||
return await db.RealEstate.findAll({
|
||||
where: query,
|
||||
limit: maxResults,
|
||||
@@ -300,7 +300,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
order
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -5,11 +5,9 @@ const Op = sequelize.Op;
|
||||
|
||||
const getSearchRequest = async searchRequestId => {
|
||||
try {
|
||||
|
||||
return await db.SearchRequest.findByPk(searchRequestId);
|
||||
|
||||
} catch (error) {
|
||||
console.log("searchrequest.js",error);
|
||||
console.log("searchrequest.js", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -116,30 +114,30 @@ const findSearchRequestsForRealEstate = async realEstate => {
|
||||
if (accessRoadType) {
|
||||
query.accessRoadType = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: 'ANY',
|
||||
[Op.eq]: "ANY",
|
||||
[Op.eq]: accessRoadType
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (balcony) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (newBuilding) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (elevator) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return await db.SearchRequest.findAll({ where: query });
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user