Added migrations and saving real estate type correctly
This commit is contained in:
11
app/config/config.json
Normal file
11
app/config/config.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"development": {
|
||||
"use_env_variable": "JAWSDB_URL"
|
||||
},
|
||||
"test": {
|
||||
"use_env_variable": "JAWSDB_URL"
|
||||
},
|
||||
"production": {
|
||||
"use_env_variable": "JAWSDB_URL"
|
||||
}
|
||||
}
|
||||
0
app/controllers/grad.js
Normal file
0
app/controllers/grad.js
Normal file
@@ -1,10 +1,10 @@
|
||||
const RealEstateRequest = require('../models/RealEstateRequest');
|
||||
const db = require('../models/index');
|
||||
|
||||
const vrsteNekretnina = [
|
||||
{ ime: "Kuća", id: "kuca" },
|
||||
{ ime: "Stan", id: "stan" },
|
||||
{ ime: "Vikendica", id: "vikendica" }
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
const getVrstaNekretnine = (req,res) => {
|
||||
@@ -15,12 +15,12 @@ const getVrstaNekretnine = (req,res) => {
|
||||
}
|
||||
|
||||
const postVrstaNekretnine = (req, res) => {
|
||||
RealEstateRequest.create({
|
||||
real_estate_type: req.body.vrsta
|
||||
db.RealEstateRequest.create({
|
||||
realEstateType: req.body.vrsta
|
||||
}).then( (result) => {
|
||||
res.send("Result is " + JSON.stringify(result));
|
||||
}).catch( (e) => {
|
||||
res.send(e);
|
||||
res.send(e);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
const Sequelize = require("sequelize");
|
||||
const sequelize = new Sequelize(process.env.JAWSDB_URL);
|
||||
|
||||
module.exports = sequelize;
|
||||
34
app/migrations/20190417035319-create-market-alert.js
Normal file
34
app/migrations/20190417035319-create-market-alert.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('MarketAlerts', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
olxUrl: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
lastDate: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('MarketAlerts');
|
||||
}
|
||||
};
|
||||
34
app/migrations/20190417035707-create-real-estate-request.js
Normal file
34
app/migrations/20190417035707-create-real-estate-request.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('RealEstateRequests', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
uniqueId: {
|
||||
type: Sequelize.UUID
|
||||
},
|
||||
realEstateType: {
|
||||
type: Sequelize.ENUM,
|
||||
values: ['kuca','stan','vikendica','plac','poslovni_prostor','apartman','garaza']
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('RealEstateRequests');
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
const Sequelize = require("sequelize");
|
||||
const sequelize = require("../db/db");
|
||||
const MarketAlert = sequelize.define("market_alert", {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true
|
||||
},
|
||||
olx_url: Sequelize.STRING,
|
||||
last_date: Sequelize.STRING,
|
||||
email: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = MarketAlert;
|
||||
@@ -1,25 +0,0 @@
|
||||
const Sequelize = require("sequelize");
|
||||
const sequelize = require("../db/db");
|
||||
const RealEstateRequest = sequelize.define("real_estate_request", {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true
|
||||
},
|
||||
unique_id: {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
allowNull: false,
|
||||
},
|
||||
real_estate_type: {
|
||||
type: Sequelize.ENUM,
|
||||
values: ['kuca', 'stan', 'vikendica']
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = RealEstateRequest;
|
||||
|
||||
37
app/models/index.js
Normal file
37
app/models/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../config/config.json')[env];
|
||||
const db = {};
|
||||
|
||||
let sequelize;
|
||||
if (config.use_env_variable) {
|
||||
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||
} else {
|
||||
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
||||
}
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = sequelize['import'](path.join(__dirname, file));
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
module.exports = db;
|
||||
15
app/models/marketalert.js
Normal file
15
app/models/marketalert.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const MarketAlert = sequelize.define('MarketAlert', {
|
||||
olxUrl: DataTypes.STRING,
|
||||
lastDate: DataTypes.STRING,
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
allowNul: false
|
||||
}
|
||||
}, {});
|
||||
MarketAlert.associate = function(models) {
|
||||
// associations can be defined here
|
||||
};
|
||||
return MarketAlert;
|
||||
};
|
||||
19
app/models/realestaterequest.js
Normal file
19
app/models/realestaterequest.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const RealEstateRequest = sequelize.define('RealEstateRequest', {
|
||||
uniqueId: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
allowNull: false
|
||||
},
|
||||
realEstateType: {
|
||||
type: DataTypes.ENUM,
|
||||
values: ['kuca','stan','vikendica','plac','poslovni_prostor','apartman','garaza']
|
||||
},
|
||||
email: DataTypes.STRING
|
||||
}, {});
|
||||
RealEstateRequest.associate = function(models) {
|
||||
// associations can be defined here
|
||||
};
|
||||
return RealEstateRequest;
|
||||
};
|
||||
@@ -26,5 +26,4 @@
|
||||
|
||||
|
||||
|
||||
<a href="<%= nextStep %>"> >>> </a>
|
||||
|
||||
|
||||
4
index.js
4
index.js
@@ -5,10 +5,10 @@ const postVrstaNekretnine = require('./app/controllers/vrsta_nekretnine').postVr
|
||||
let express = require("express");
|
||||
const path = require("path");
|
||||
const bodyParser = require("body-parser");
|
||||
const MarketAlert = require("./app/models/MarketAlert");
|
||||
const MarketAlert = require("./app/models/marketalert");
|
||||
const sendNotification = require("./app/lib/sendnotification");
|
||||
const scrapTheItems = require("./app/lib/scraptheitems");
|
||||
const sequelize = require("./app/db/db");
|
||||
const sequelize = require("./app/models/index").sequelize;
|
||||
const Twocheckout = require("2checkout-node");
|
||||
const layout = require('express-layout');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user