stop crawling when existing, non-renewed ad is found

This commit is contained in:
Bilal Catic
2019-09-24 23:23:09 +02:00
parent 746732f30b
commit 90bc57edb6
4 changed files with 155 additions and 61 deletions

View File

@@ -1,7 +1,8 @@
"use strict";
const db = require("../../models/index");
const sequelize = require("sequelize");
const bulkUpsertRealEstates = async (realEstateData, maxAge) => {
const bulkUpsertRealEstates = async realEstateData => {
try {
const fieldsToUpdateIfDuplicate = [
"realEstateType",
@@ -23,16 +24,42 @@ const bulkUpsertRealEstates = async (realEstateData, maxAge) => {
"longDescription",
"gardenSize",
"adStatus",
"updatedAt"
"updatedAt",
"renewedDate"
];
return await db.RealEstate.bulkCreate(realEstateData, {
updateOnDuplicate: fieldsToUpdateIfDuplicate
updateOnDuplicate: fieldsToUpdateIfDuplicate,
returning: true
});
} catch (e) {
console.log("Error bulk upserting realEstates : ", e);
}
};
module.exports = {
bulkUpsertRealEstates
const checkIfAlreadyExist = async realEstateData => {
const orQueryPart = [];
for (const realEstate of realEstateData) {
const { agencyObjectId, originAgencyName } = realEstate;
const singleRealEstateQueryPart = {
agencyObjectId,
originAgencyName
};
orQueryPart.push(singleRealEstateQueryPart);
}
const query = {
[sequelize.Op.or]: orQueryPart
};
const result = await db.RealEstate.count({ where: query });
return result > 0;
};
module.exports = {
bulkUpsertRealEstates,
checkIfAlreadyExist
};