return new and existing real estates when saving results

This commit is contained in:
Bilal Catic
2019-09-25 08:32:37 +02:00
parent f93d0e738f
commit b3fcc6ba9a
2 changed files with 26 additions and 47 deletions

View File

@@ -1,6 +1,5 @@
"use strict";
const db = require("../../models/index");
const sequelize = require("sequelize");
const bulkUpsertRealEstates = async realEstateData => {
try {
@@ -37,29 +36,6 @@ const bulkUpsertRealEstates = async realEstateData => {
}
};
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
bulkUpsertRealEstates
};