diff --git a/app/helpers/db/realEstate.js b/app/helpers/db/realEstate.js new file mode 100644 index 0000000..3f32b7c --- /dev/null +++ b/app/helpers/db/realEstate.js @@ -0,0 +1,38 @@ +"use strict"; +const db = require("../../models/index"); + +const bulkUpsertRealEstates = async realEstateData => { + try { + const fieldsToUpdateIfDuplicate = [ + "realEstateType", + "adType", + "price", + "area", + "streetNumber", + "streetName", + "locality", + "municipality", + "city", + "region", + "entity", + "country", + "locationLat", + "locationLong", + "title", + "shortDescription", + "longDescription", + "gardenSize", + "adStatus", + "updatedAt" + ]; + return await db.RealEstate.bulkCreate(realEstateData, { + updateOnDuplicate: fieldsToUpdateIfDuplicate + }); + } catch (e) { + console.log("Error bulk upserting realEstates : ", e); + } +}; + +module.exports = { + bulkUpsertRealEstates +}; diff --git a/app/models/realEstate.js b/app/models/realEstate.js index 66b7a92..72b76ec 100644 --- a/app/models/realEstate.js +++ b/app/models/realEstate.js @@ -12,13 +12,15 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.TEXT, allowNull: false }, - agencyObjectId: { - type: DataTypes.TEXT, - allowNull: false - }, originAgencyName: { type: DataTypes.TEXT, - allowNull: false + allowNull: false, + unique: true + }, + agencyObjectId: { + type: DataTypes.TEXT, + allowNull: false, + unique: true }, realEstateType: { type: DataTypes.TEXT, @@ -45,14 +47,10 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.DATE, allowNull: false }, - deleted: { - type: DataTypes.BOOLEAN, - allowNull: false - }, - sold: { - type: DataTypes.BOOLEAN, - allowNull: false - } + title: DataTypes.TEXT, + shortDescription: DataTypes.TEXT, + longDescription: DataTypes.TEXT, + adStatus: DataTypes.INTEGER }); RealEstate.associate = models => {