Added price history log.
This commit is contained in:
@@ -27,9 +27,7 @@ class PostgresSaver {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const savedPrices = await bulkUpsertPriceHistory(resultPrices);
|
const savedPrices = await bulkUpsertPriceHistory(resultPrices);
|
||||||
//
|
|
||||||
console.log("savedPrices", savedPrices);
|
|
||||||
//
|
|
||||||
if (Array.isArray(savedRecords)) {
|
if (Array.isArray(savedRecords)) {
|
||||||
const newRealEstates = [];
|
const newRealEstates = [];
|
||||||
const existingRealEstates = [];
|
const existingRealEstates = [];
|
||||||
|
|||||||
@@ -63,9 +63,7 @@ const bulkUpsertRealEstates = async realEstateData => {
|
|||||||
"numberOfViewsAgency"
|
"numberOfViewsAgency"
|
||||||
];
|
];
|
||||||
const order = [["updatedAt", "desc"]];
|
const order = [["updatedAt", "desc"]];
|
||||||
//
|
|
||||||
//console.log("realEstateData:", realEstateData);
|
|
||||||
//
|
|
||||||
return await db.RealEstate.bulkCreate(realEstateData, {
|
return await db.RealEstate.bulkCreate(realEstateData, {
|
||||||
updateOnDuplicate: fieldsToUpdateIfDuplicate,
|
updateOnDuplicate: fieldsToUpdateIfDuplicate,
|
||||||
returning: true,
|
returning: true,
|
||||||
|
|||||||
@@ -1,11 +1,26 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const { RealEstate } = require("../models");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: (queryInterface, Sequelize) => {
|
async up(queryInterface, Sequelize) {
|
||||||
// ??
|
//Reading initial data from RealEstate table in db
|
||||||
const realEstateInitialData = await queryInterface.Sequelize.findall ();
|
const realEstateInitialData = await RealEstate.findAll();
|
||||||
const priceHistoryInitialData = realEstateInitialData.map ();
|
//Extruding data for table PriceHistory
|
||||||
|
const priceHistoryInitialData = realEstateInitialData.map(realEstate => {
|
||||||
|
//Null values canot be recognized by ignore duplicates in sequalize
|
||||||
|
//Value price = 0 indicates 'cijena na upit'
|
||||||
|
const priceTmp =
|
||||||
|
realEstate.dataValues.price === null ? 0 : realEstate.dataValues.price;
|
||||||
|
|
||||||
|
return {
|
||||||
|
realEstateId: realEstate.dataValues.id,
|
||||||
|
price: priceTmp,
|
||||||
|
createdAt: realEstate.dataValues.createdAt,
|
||||||
|
updatedAt: realEstate.dataValues.updatedAt
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return queryInterface.bulkInsert(
|
return queryInterface.bulkInsert(
|
||||||
"PriceHistory",
|
"PriceHistory",
|
||||||
priceHistoryInitialData,
|
priceHistoryInitialData,
|
||||||
@@ -13,7 +28,7 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
async down(queryInterface, Sequelize) {
|
||||||
return queryInterface.bulkDelete("PriceHistory", null, {});
|
return queryInterface.bulkDelete("PriceHistory", null, {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"start": "node ./index.js",
|
"start": "node ./index.js",
|
||||||
"start-mon": "nodemon ./index.js",
|
"start-mon": "nodemon ./index.js",
|
||||||
"migrate": "cd app && npx sequelize db:migrate",
|
"migrate": "cd app && npx sequelize db:migrate",
|
||||||
|
"seed": "cd app && npx sequelize db:seed:all",
|
||||||
"setup": "docker build -t marketalerts . && docker run -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=marketalerts --name pg_marketalerts -d -p 5432:5432 marketalerts && sleep 10 && npm run migrate",
|
"setup": "docker build -t marketalerts . && docker run -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=marketalerts --name pg_marketalerts -d -p 5432:5432 marketalerts && sleep 10 && npm run migrate",
|
||||||
"docker-start": "docker start pg_marketalerts",
|
"docker-start": "docker start pg_marketalerts",
|
||||||
"docker-stop": "docker stop pg_marketalerts",
|
"docker-stop": "docker stop pg_marketalerts",
|
||||||
|
|||||||
Reference in New Issue
Block a user