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
|
||||
};
|
||||
Reference in New Issue
Block a user