Skip to content

Commit

Permalink
Merge pull request #19 from FACG4/db-basic-steup
Browse files Browse the repository at this point in the history
Fix the database related issues #15 #16 #17
  • Loading branch information
NouraldinS authored Jul 26, 2018
2 parents bb60785 + c2ff46e commit f6f203a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
export default app;
103 changes: 103 additions & 0 deletions server/database/data/mock_data.js
Original file line number Diff line number Diff line change
@@ -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: '[email protected]'
});

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: '[email protected]',
phone: '0599194310',
notify_me: true,
flight_id: 1
},
{
first_name: 'Balsam',
last_name: 'Ashi',
email: '[email protected]',
phone: '0599000001',
notify_me: true,
flight_id: 1
},
{
first_name: 'Inass',
last_name: 'T.',
email: '[email protected]',
phone: '05990000002',
notify_me: false,
flight_id: 1
},
{
first_name: 'Ramy',
last_name: 'Shurafa',
email: '[email protected]',
phone: '05990000003',
notify_me: true,
flight_id: 1
},
{
first_name: 'John',
last_name: 'Rees',
email: '[email protected]',
phone: '05990000004',
notify_me: true,
flight_id: 2
},
{
first_name: 'Root',
last_name: 'Sam',
email: '[email protected]',
phone: '05990000006',
notify_me: true,
flight_id: 2
},
{
first_name: 'Finch',
last_name: 'H.',
email: '[email protected]',
phone: '05990000009',
notify_me: true,
flight_id: 2
},
]);
await models.sequelize.close();
});
2 changes: 1 addition & 1 deletion server/database/models/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default (sequelize, DataTypes) => {
unique: true
},
notify_me: {
type: DataTypes.STRING(20)
type: DataTypes.BOOLEAN
}
});
return Customers;
Expand Down
4 changes: 2 additions & 2 deletions server/database/models/flights.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (sequelize, DataTypes) => {
airport: {
type: DataTypes.STRING
},
flight_id: {
flight_no: {
type: DataTypes.STRING,
unique: true
},
Expand All @@ -19,7 +19,7 @@ export default (sequelize, DataTypes) => {
departure_time: {
type: DataTypes.DATE
},
flight_time: {
arrival_time: {
type: DataTypes.DATE
},
gate: {
Expand Down
5 changes: 3 additions & 2 deletions server/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand Down

0 comments on commit f6f203a

Please sign in to comment.