First review changes: applied prettier, ternary and changed accesRoadType filter
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.env
|
.env
|
||||||
.idea/
|
.idea/
|
||||||
|
.eslintrc
|
||||||
|
.vscode/
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
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 bulkUpsertRealEstates = async realEstateData => {
|
const bulkUpsertRealEstates = async realEstateData => {
|
||||||
try {
|
try {
|
||||||
const fieldsToUpdateIfDuplicate = [
|
const fieldsToUpdateIfDuplicate = [
|
||||||
@@ -131,42 +130,36 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
|||||||
|
|
||||||
//General queries contain only attributes that are defined for every searchreq
|
//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 = {
|
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: {
|
[Op.and]: geoSearchQueryPart
|
||||||
[Op.or]: {
|
};
|
||||||
[Op.eq]: 'ANY',
|
|
||||||
[Op.eq]: accessRoadType
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[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
|
||||||
@@ -174,133 +167,129 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
|||||||
[Op.is]: null
|
[Op.is]: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
accessRoadType: {
|
|
||||||
[Op.or]: {
|
|
||||||
[Op.eq]: 'ANY',
|
|
||||||
[Op.eq]: accessRoadType,
|
|
||||||
[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
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessRoadType !== "ANY") {
|
||||||
|
query.accessRoadType = {
|
||||||
|
[Op.eq]: accessRoadType
|
||||||
|
};
|
||||||
|
queryIncludeIncomplete.accessRoadType = {
|
||||||
|
[Op.or]: {
|
||||||
|
[Op.eq]: accessRoadType,
|
||||||
|
[Op.is]: null
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const order = [["updatedAt", "desc"]];
|
const order = [["updatedAt", "desc"]];
|
||||||
|
|
||||||
if(!includeIncompleteAds) {
|
return db.RealEstate.findAll({
|
||||||
return await db.RealEstate.findAll({
|
where: includeIncompleteAds ? queryIncludeIncomplete : query,
|
||||||
where: query,
|
limit: maxResults,
|
||||||
limit: maxResults,
|
order
|
||||||
order
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return await db.RealEstate.findAll({
|
|
||||||
where: queryIncludeIncomplete,
|
|
||||||
limit: maxResults,
|
|
||||||
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,30 +114,30 @@ 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 });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
26
package-lock.json
generated
26
package-lock.json
generated
@@ -1052,6 +1052,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
|
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
|
||||||
},
|
},
|
||||||
|
"eslint-plugin-prettier": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-GlolCC9y3XZfv3RQfwGew7NnuFDKsfI4lbvRK+PIIo23SFH+LemGs4cKwzAaRa+Mdb+lQO/STaIayno8T5sJJA==",
|
||||||
|
"requires": {
|
||||||
|
"prettier-linter-helpers": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"etag": {
|
"etag": {
|
||||||
"version": "1.8.1",
|
"version": "1.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
||||||
@@ -1271,6 +1279,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",
|
||||||
"integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk="
|
"integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk="
|
||||||
},
|
},
|
||||||
|
"fast-diff": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w=="
|
||||||
|
},
|
||||||
"fast-json-stable-stringify": {
|
"fast-json-stable-stringify": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
||||||
@@ -3179,6 +3192,19 @@
|
|||||||
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
|
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"prettier": {
|
||||||
|
"version": "1.19.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
|
||||||
|
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew=="
|
||||||
|
},
|
||||||
|
"prettier-linter-helpers": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==",
|
||||||
|
"requires": {
|
||||||
|
"fast-diff": "^1.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"process-nextick-args": {
|
"process-nextick-args": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"dotenv": "^7.0.0",
|
"dotenv": "^7.0.0",
|
||||||
"ejs": "^2.6.1",
|
"ejs": "^2.6.1",
|
||||||
|
"eslint-plugin-prettier": "^3.1.2",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"express-ejs-layouts": "^2.5.0",
|
"express-ejs-layouts": "^2.5.0",
|
||||||
"express-layout": "^0.1.0",
|
"express-layout": "^0.1.0",
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"node-schedule": "^1.3.2",
|
"node-schedule": "^1.3.2",
|
||||||
"pg": "^7.10.0",
|
"pg": "^7.10.0",
|
||||||
|
"prettier": "^1.19.1",
|
||||||
"react-step-wizard": "^5.1.0",
|
"react-step-wizard": "^5.1.0",
|
||||||
"sequelize": "^5.18.4",
|
"sequelize": "^5.18.4",
|
||||||
"sequelize-cli": "^5.5.0"
|
"sequelize-cli": "^5.5.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user