Added price history log.
This commit is contained in:
@@ -27,9 +27,7 @@ class PostgresSaver {
|
||||
};
|
||||
});
|
||||
const savedPrices = await bulkUpsertPriceHistory(resultPrices);
|
||||
//
|
||||
console.log("savedPrices", savedPrices);
|
||||
//
|
||||
|
||||
if (Array.isArray(savedRecords)) {
|
||||
const newRealEstates = [];
|
||||
const existingRealEstates = [];
|
||||
|
||||
@@ -63,9 +63,7 @@ const bulkUpsertRealEstates = async realEstateData => {
|
||||
"numberOfViewsAgency"
|
||||
];
|
||||
const order = [["updatedAt", "desc"]];
|
||||
//
|
||||
//console.log("realEstateData:", realEstateData);
|
||||
//
|
||||
|
||||
return await db.RealEstate.bulkCreate(realEstateData, {
|
||||
updateOnDuplicate: fieldsToUpdateIfDuplicate,
|
||||
returning: true,
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
const { RealEstate } = require("../models");
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
// ??
|
||||
const realEstateInitialData = await queryInterface.Sequelize.findall ();
|
||||
const priceHistoryInitialData = realEstateInitialData.map ();
|
||||
|
||||
async up(queryInterface, Sequelize) {
|
||||
//Reading initial data from RealEstate table in db
|
||||
const realEstateInitialData = await RealEstate.findAll();
|
||||
//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(
|
||||
"PriceHistory",
|
||||
priceHistoryInitialData,
|
||||
@@ -13,7 +28,7 @@ module.exports = {
|
||||
);
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
async down(queryInterface, Sequelize) {
|
||||
return queryInterface.bulkDelete("PriceHistory", null, {});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"start": "node ./index.js",
|
||||
"start-mon": "nodemon ./index.js",
|
||||
"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",
|
||||
"docker-start": "docker start pg_marketalerts",
|
||||
"docker-stop": "docker stop pg_marketalerts",
|
||||
|
||||
Reference in New Issue
Block a user