diff --git a/server/app.js b/server/app.js index 5155e0c..5401c03 100644 --- a/server/app.js +++ b/server/app.js @@ -3,11 +3,11 @@ import path from 'path'; const app = express(); -app.set('port', process.env.PORT || 9000) +app.set('port', process.env.PORT || 9000); app.use(express.static(path.join(__dirname, '..', 'client', 'build'))); app.get('/', function (req, res) { res.sendFile(path.join(__dirname, '..', 'client', 'build', 'index.html')); }); -export default app; \ No newline at end of file +export default app; diff --git a/server/database/data/mock_data.js b/server/database/data/mock_data.js index e69de29..4a36bf8 100644 --- a/server/database/data/mock_data.js +++ b/server/database/data/mock_data.js @@ -0,0 +1,103 @@ +import models from '../models/index'; + +models.sequelize + .authenticate() + .then(() => { + console.log('Connection has been established successfully.'); + }) + .catch((err) => { + console.error('Unable to connect to the database:', err); + }); + +models.sequelize.sync({ force: true }).then(async () => { + await models.Admin.create({ + username: 'admin', + password: 'admin', + email: 'admin@admin.com' + }); + + await models.Flights.bulkCreate([ + { + airline: 'Gaza Airlines', + airport: 'Gaza Airport', + flight_no: 'GA001', + origin: 'Gaza', + destination: 'Berlin', + departure_time: '09-15-2018 22:00:00', + arrival_time: '09-16-2018 09:00:00', + gate: 'W-10', + aircraft: 'BW', + }, + { + airline: 'Nigeria Airlines', + airport: 'Lagos', + flight_no: 'NA001', + origin: 'Lagos', + destination: 'Aboja', + departure_time: '09-15-2018 22:00:00', + arrival_time: '09-16-2018 09:00:00', + gate: 'W-10', + aircraft: 'BW', + }, + + ]); + await models.Customers.bulkCreate([ + { + first_name: 'Abdalsamad', + last_name: 'Abumusameh', + email: 'abdalsamad.y.m@gmail.com', + phone: '0599194310', + notify_me: true, + flight_id: 1 + }, + { + first_name: 'Balsam', + last_name: 'Ashi', + email: 'balsam@gmail.com', + phone: '0599000001', + notify_me: true, + flight_id: 1 + }, + { + first_name: 'Inass', + last_name: 'T.', + email: 'inass@gmail.com', + phone: '05990000002', + notify_me: false, + flight_id: 1 + }, + { + first_name: 'Ramy', + last_name: 'Shurafa', + email: 'Ramy@gmail.com', + phone: '05990000003', + notify_me: true, + flight_id: 1 + }, + { + first_name: 'John', + last_name: 'Rees', + email: 'rees@gmail.com', + phone: '05990000004', + notify_me: true, + flight_id: 2 + }, + { + first_name: 'Root', + last_name: 'Sam', + email: 'root@gmail.com', + phone: '05990000006', + notify_me: true, + flight_id: 2 + }, + { + first_name: 'Finch', + last_name: 'H.', + email: 'finch@gmail.com', + phone: '05990000009', + notify_me: true, + flight_id: 2 + }, + ]); + await models.sequelize.close(); +}); diff --git a/server/database/models/customers.js b/server/database/models/customers.js index 3caee33..28fd7cd 100644 --- a/server/database/models/customers.js +++ b/server/database/models/customers.js @@ -17,7 +17,7 @@ export default (sequelize, DataTypes) => { unique: true }, notify_me: { - type: DataTypes.STRING(20) + type: DataTypes.BOOLEAN } }); return Customers; diff --git a/server/database/models/flights.js b/server/database/models/flights.js index 2d8584e..65f8830 100644 --- a/server/database/models/flights.js +++ b/server/database/models/flights.js @@ -6,7 +6,7 @@ export default (sequelize, DataTypes) => { airport: { type: DataTypes.STRING }, - flight_id: { + flight_no: { type: DataTypes.STRING, unique: true }, @@ -19,7 +19,7 @@ export default (sequelize, DataTypes) => { departure_time: { type: DataTypes.DATE }, - flight_time: { + arrival_time: { type: DataTypes.DATE }, gate: { diff --git a/server/database/models/index.js b/server/database/models/index.js index 4203a82..c390619 100644 --- a/server/database/models/index.js +++ b/server/database/models/index.js @@ -7,9 +7,10 @@ models.Flights = sequelize.import('./flights'); models.Customers = sequelize.import('./customers'); // Relations; -models.Customers.belongsTo(models.Flights, { + +models.Flights.hasMany(models.Customers, { onDelete: 'CASCADE', - foreignKey: 'customer_id', + foreignKey: 'flight_id', targetKey: 'id', });