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