stop crawling when existing, non-renewed ad is found
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user