return new and existing real estates when saving results
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user