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,
|
||||
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 => {
|
||||
|
||||
Reference in New Issue
Block a user