update RealEstates model, add DB helper functions for RealEstates model
This commit is contained in:
38
app/helpers/db/realEstate.js
Normal file
38
app/helpers/db/realEstate.js
Normal file
@@ -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
|
||||||
|
};
|
||||||
@@ -12,13 +12,15 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
agencyObjectId: {
|
|
||||||
type: DataTypes.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
originAgencyName: {
|
originAgencyName: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
|
},
|
||||||
|
agencyObjectId: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
},
|
},
|
||||||
realEstateType: {
|
realEstateType: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
@@ -45,14 +47,10 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
deleted: {
|
title: DataTypes.TEXT,
|
||||||
type: DataTypes.BOOLEAN,
|
shortDescription: DataTypes.TEXT,
|
||||||
allowNull: false
|
longDescription: DataTypes.TEXT,
|
||||||
},
|
adStatus: DataTypes.INTEGER
|
||||||
sold: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
allowNull: false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RealEstate.associate = models => {
|
RealEstate.associate = models => {
|
||||||
|
|||||||
Reference in New Issue
Block a user