Compare commits
1 Commits
price-hist
...
sliders-fo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6725355a0 |
@@ -7,7 +7,42 @@ const PRICE_SLIDER_OPTIONS_SALE = {
|
|||||||
step: 1000,
|
step: 1000,
|
||||||
connect: true
|
connect: true
|
||||||
};
|
};
|
||||||
|
const FLAT_PRICE_SLIDER_OPTIONS_SALE = {
|
||||||
|
start: [50000, 150000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [800000]
|
||||||
|
},
|
||||||
|
step: 5000,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
|
const HOUSE_PRICE_SLIDER_OPTIONS_SALE = {
|
||||||
|
start: [50000, 150000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [1500000]
|
||||||
|
},
|
||||||
|
step: 10000,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
|
const OFFICE_PRICE_SLIDER_OPTIONS_SALE = {
|
||||||
|
start: [15000, 50000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [2000000]
|
||||||
|
},
|
||||||
|
step: 2000,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
|
const LAND_PRICE_SLIDER_OPTIONS_SALE = {
|
||||||
|
start: [40000, 80000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [2000000]
|
||||||
|
},
|
||||||
|
step: 10000,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
const PRICE_SLIDER_OPTIONS_RENT = {
|
const PRICE_SLIDER_OPTIONS_RENT = {
|
||||||
start: [300, 500],
|
start: [300, 500],
|
||||||
range: {
|
range: {
|
||||||
@@ -17,18 +52,62 @@ const PRICE_SLIDER_OPTIONS_RENT = {
|
|||||||
step: 50,
|
step: 50,
|
||||||
connect: true
|
connect: true
|
||||||
};
|
};
|
||||||
|
const FLAT_PRICE_SLIDER_OPTIONS_RENT = {
|
||||||
|
start: [300, 600],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [4000]
|
||||||
|
},
|
||||||
|
step: 100,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
|
const HOUSE_PRICE_SLIDER_OPTIONS_RENT = {
|
||||||
|
start: [500, 1000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [10000]
|
||||||
|
},
|
||||||
|
step: 100,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
|
const OFFICE_PRICE_SLIDER_OPTIONS_RENT = {
|
||||||
|
start: [200, 1000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [20000]
|
||||||
|
},
|
||||||
|
step: 100,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
|
const LAND_PRICE_SLIDER_OPTIONS_RENT = {
|
||||||
|
start: [500, 1000],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [20000]
|
||||||
|
},
|
||||||
|
step: 100,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
//This will be used for Flats, Apartments, Houses
|
//This will be used for Flats, Apartments, Houses
|
||||||
const HOME_SIZE_SLIDER_OPTIONS = {
|
const HOME_SIZE_SLIDER_OPTIONS = {
|
||||||
start: [30, 75],
|
start: [30, 75],
|
||||||
range: {
|
range: {
|
||||||
min: [0],
|
min: [0],
|
||||||
max: [400]
|
max: [500]
|
||||||
},
|
},
|
||||||
step: 5,
|
step: 5,
|
||||||
connect: true
|
connect: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const OFFICE_SIZE_SLIDER_OPTIONS = {
|
||||||
|
start: [30, 150],
|
||||||
|
range: {
|
||||||
|
min: [0],
|
||||||
|
max: [1200]
|
||||||
|
},
|
||||||
|
step: 10,
|
||||||
|
connect: true
|
||||||
|
};
|
||||||
const GARDEN_SIZE_SLIDER_OPTIONS = {
|
const GARDEN_SIZE_SLIDER_OPTIONS = {
|
||||||
start: [100, 1000],
|
start: [100, 1000],
|
||||||
range: {
|
range: {
|
||||||
@@ -111,8 +190,8 @@ const AD_CATEGORY = {
|
|||||||
hasNumberOfRoom: true,
|
hasNumberOfRoom: true,
|
||||||
hasNumberOfFloors: false,
|
hasNumberOfFloors: false,
|
||||||
hasFloorProp: true,
|
hasFloorProp: true,
|
||||||
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
|
priceSliderOptionsSale: FLAT_PRICE_SLIDER_OPTIONS_SALE,
|
||||||
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
|
priceSliderOptionsRent: FLAT_PRICE_SLIDER_OPTIONS_RENT,
|
||||||
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
|
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
|
||||||
},
|
},
|
||||||
HOUSE: {
|
HOUSE: {
|
||||||
@@ -126,8 +205,8 @@ const AD_CATEGORY = {
|
|||||||
hasNumberOfRoom: true,
|
hasNumberOfRoom: true,
|
||||||
hasNumberOfFloors: true,
|
hasNumberOfFloors: true,
|
||||||
hasFloorProp: false,
|
hasFloorProp: false,
|
||||||
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
|
priceSliderOptionsSale: HOUSE_PRICE_SLIDER_OPTIONS_SALE,
|
||||||
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
|
priceSliderOptionsRent: HOUSE_PRICE_SLIDER_OPTIONS_RENT,
|
||||||
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS,
|
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS,
|
||||||
gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS
|
gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS
|
||||||
},
|
},
|
||||||
@@ -142,9 +221,9 @@ const AD_CATEGORY = {
|
|||||||
hasNumberOfRoom: true,
|
hasNumberOfRoom: true,
|
||||||
hasNumberOfFloors: false,
|
hasNumberOfFloors: false,
|
||||||
hasFloorProp: true,
|
hasFloorProp: true,
|
||||||
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
|
priceSliderOptionsSale: OFFICE_PRICE_SLIDER_OPTIONS_SALE,
|
||||||
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
|
priceSliderOptionsRent: OFFICE_PRICE_SLIDER_OPTIONS_RENT,
|
||||||
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
|
sizeSliderOptions: OFFICE_SIZE_SLIDER_OPTIONS
|
||||||
},
|
},
|
||||||
LAND: {
|
LAND: {
|
||||||
id: "LAND",
|
id: "LAND",
|
||||||
@@ -157,8 +236,8 @@ const AD_CATEGORY = {
|
|||||||
hasNumberOfRoom: false,
|
hasNumberOfRoom: false,
|
||||||
hasNumberOfFloors: false,
|
hasNumberOfFloors: false,
|
||||||
hasFloorProp: false,
|
hasFloorProp: false,
|
||||||
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
|
priceSliderOptionsSale: LAND_PRICE_SLIDER_OPTIONS_SALE,
|
||||||
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
|
priceSliderOptionsRent: LAND_PRICE_SLIDER_OPTIONS_RENT,
|
||||||
sizeSliderOptions: LAND_SIZE_SLIDER_OPTIONS
|
sizeSliderOptions: LAND_SIZE_SLIDER_OPTIONS
|
||||||
},
|
},
|
||||||
APARTMENT: {
|
APARTMENT: {
|
||||||
@@ -172,8 +251,8 @@ const AD_CATEGORY = {
|
|||||||
hasNumberOfRoom: true,
|
hasNumberOfRoom: true,
|
||||||
hasNumberOfFloors: false,
|
hasNumberOfFloors: false,
|
||||||
hasFloorProp: true,
|
hasFloorProp: true,
|
||||||
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
|
priceSliderOptionsSale: FLAT_PRICE_SLIDER_OPTIONS_SALE,
|
||||||
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
|
priceSliderOptionsRent: FLAT_PRICE_SLIDER_OPTIONS_RENT,
|
||||||
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
|
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS
|
||||||
},
|
},
|
||||||
GARAGE: {
|
GARAGE: {
|
||||||
@@ -202,8 +281,8 @@ const AD_CATEGORY = {
|
|||||||
hasNumberOfRoom: true,
|
hasNumberOfRoom: true,
|
||||||
hasNumberOfFloors: true,
|
hasNumberOfFloors: true,
|
||||||
hasFloorProp: false,
|
hasFloorProp: false,
|
||||||
priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE,
|
priceSliderOptionsSale: HOUSE_PRICE_SLIDER_OPTIONS_SALE,
|
||||||
priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT,
|
priceSliderOptionsRent: HOUSE_PRICE_SLIDER_OPTIONS_RENT,
|
||||||
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS,
|
sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS,
|
||||||
gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS
|
gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
|
|
||||||
const { bulkUpsertRealEstates } = require("../../helpers/db/realEstate");
|
const { bulkUpsertRealEstates } = require("../../helpers/db/realEstate");
|
||||||
const { bulkUpsertPriceHistory } = require("../../helpers/db/priceHistory");
|
|
||||||
|
|
||||||
class PostgresSaver {
|
class PostgresSaver {
|
||||||
connect() {
|
connect() {
|
||||||
@@ -12,21 +11,6 @@ class PostgresSaver {
|
|||||||
|
|
||||||
async save(results) {
|
async save(results) {
|
||||||
const savedRecords = await bulkUpsertRealEstates(results);
|
const savedRecords = await bulkUpsertRealEstates(results);
|
||||||
//Extruding data for price history table
|
|
||||||
const resultPrices = savedRecords.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
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const savedPrices = await bulkUpsertPriceHistory(resultPrices);
|
|
||||||
|
|
||||||
if (Array.isArray(savedRecords)) {
|
if (Array.isArray(savedRecords)) {
|
||||||
const newRealEstates = [];
|
const newRealEstates = [];
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const db = require("../../models/index");
|
|
||||||
const sequelize = require("sequelize");
|
|
||||||
|
|
||||||
const bulkUpsertPriceHistory = async priceHistoryData => {
|
|
||||||
try {
|
|
||||||
const order = [["realEstateId", "desc"]];
|
|
||||||
|
|
||||||
return await db.PriceHistory.bulkCreate(priceHistoryData, {
|
|
||||||
order,
|
|
||||||
ignoreDuplicates: true
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Error bulk upserting priceHistory : ", e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
bulkUpsertPriceHistory
|
|
||||||
};
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
const tableFields = {
|
|
||||||
id: {
|
|
||||||
type: Sequelize.BIGINT,
|
|
||||||
autoIncrement: true,
|
|
||||||
allowNull: false,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
realEstateId: {
|
|
||||||
type: Sequelize.BIGINT,
|
|
||||||
allowNull: false,
|
|
||||||
unique: "uniquePriceRealEstate",
|
|
||||||
references: {
|
|
||||||
model: "RealEstates",
|
|
||||||
key: "id"
|
|
||||||
},
|
|
||||||
onUpdate: "CASCADE",
|
|
||||||
onDelete: "SET NULL"
|
|
||||||
},
|
|
||||||
price: {
|
|
||||||
type: Sequelize.REAL,
|
|
||||||
unique: "uniquePriceRealEstate"
|
|
||||||
},
|
|
||||||
createdAt: {
|
|
||||||
type: Sequelize.DATE,
|
|
||||||
defaultValue: Sequelize.literal("NOW()")
|
|
||||||
},
|
|
||||||
updatedAt: {
|
|
||||||
type: Sequelize.DATE,
|
|
||||||
defaultValue: Sequelize.literal("NOW()")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return queryInterface.createTable("PriceHistory", tableFields);
|
|
||||||
},
|
|
||||||
|
|
||||||
down: queryInterface => {
|
|
||||||
return queryInterface.dropTable("PriceHistory", {});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) =>
|
|
||||||
queryInterface.addConstraint("PriceHistory", ["realEstateId", "price"], {
|
|
||||||
type: "unique",
|
|
||||||
name: "uniquePriceRealEstate"
|
|
||||||
}),
|
|
||||||
down: queryInterface =>
|
|
||||||
queryInterface.removeConstraint("PriceHistory", "uniquePriceRealEstate")
|
|
||||||
};
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = (sequalize, DataTypes) => {
|
|
||||||
const PriceHistory = sequalize.define(
|
|
||||||
"PriceHistory",
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
type: DataTypes.BIGINT,
|
|
||||||
autoIncrement: true,
|
|
||||||
primaryKey: true,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
realEstateId: {
|
|
||||||
type: DataTypes.BIGINT,
|
|
||||||
allowNull: false,
|
|
||||||
unique: "uniquePriceRealEstate",
|
|
||||||
references: {
|
|
||||||
model: "RealEstates",
|
|
||||||
key: "id"
|
|
||||||
},
|
|
||||||
onUpdate: "CASCADE",
|
|
||||||
onDelete: "SET NULL"
|
|
||||||
},
|
|
||||||
price: {
|
|
||||||
type: DataTypes.REAL,
|
|
||||||
unique: "uniquePriceRealEstate"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
freezeTableName: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
PriceHistory.associate = models => {
|
|
||||||
PriceHistory.hasMany(models.RealEstate, {
|
|
||||||
foreignKey: "id",
|
|
||||||
sourceKey: "realEstateId",
|
|
||||||
targetKey: "id",
|
|
||||||
as: "realEstates"
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return PriceHistory;
|
|
||||||
};
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
const { RealEstate } = require("../models");
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
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,
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
return queryInterface.bulkDelete("PriceHistory", null, {});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
"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