-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#13 - Added support for modified the database structure from the code
- Added driver table - Added driver_car table - Added driver_ride table - Created initial prototype for sending sms - Moved some mysql configurations
- Loading branch information
1 parent
568396b
commit 1e29661
Showing
15 changed files
with
168 additions
and
15 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
infrastructure/services/database/changes/2018-08-04-1-create-location-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS location ( | ||
id INT(11), | ||
location GEOMETRY NOT NULL, | ||
suburb TEXT, | ||
placeName TEXT, | ||
postCode VARCHAR(10) | ||
); |
21 changes: 21 additions & 0 deletions
21
infrastructure/services/database/changes/2018-08-04-2-create-rides-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE IF NOT EXISTS rides ( | ||
id INT(11) PRIMARY KEY, | ||
client VARCHAR(255), | ||
facilitatorEmail VARCHAR(255), | ||
pickupTimeAndDateInUTC DATETIME, | ||
locationFrom POINT, | ||
locationTo POINT, | ||
fbLink VARCHAR(255), | ||
driverGender VARCHAR(10), | ||
carType VARCHAR(255), | ||
status ENUM('OPEN','CONFIRMED','ENDED','CANCELLED') DEFAULT 'OPEN', | ||
deleted TINYINT(4), | ||
suburbFrom VARCHAR(255), | ||
placeNameFrom VARCHAR(255), | ||
postCodeFrom VARCHAR(10), | ||
suburbTo VARCHAR(255), | ||
placeNameTo VARCHAR(255), | ||
postCodeTo VARCHAR(10), | ||
description VARCHAR(1024) | ||
); | ||
|
7 changes: 7 additions & 0 deletions
7
infrastructure/services/database/changes/2018-08-04-3-create-driver-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS driver ( | ||
id INT(11) PRIMARY KEY, | ||
name VARCHAR(255), | ||
phone VARCHAR(20), | ||
facebookUrl VARCHAR(255) | ||
); | ||
|
8 changes: 8 additions & 0 deletions
8
infrastructure/services/database/changes/2018-08-04-4-create-driver_car-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE IF NOT EXISTS driver_car ( | ||
id INT(11) PRIMARY KEY, | ||
driver_id INT(11), | ||
carModel VARCHAR(255), | ||
color VARCHAR(255), | ||
licensePlateNumber VARCHAR(255), | ||
FOREIGN KEY (driver_id) REFERENCES driver(id) | ||
); |
10 changes: 10 additions & 0 deletions
10
infrastructure/services/database/changes/2018-08-04-5-create-driver_ride-table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE IF NOT EXISTS driver_ride ( | ||
id INT(11) PRIMARY KEY, | ||
driver_id INT(11), | ||
ride_id INT(11), | ||
confirmed TINYINT(1), | ||
notified24h TINYINT(1), | ||
notified5m TINYINT(1), | ||
FOREIGN KEY (driver_id) REFERENCES driver(id), | ||
FOREIGN KEY (ride_id) REFERENCES rides(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const connection = () => mysql.createConnection({ | ||
host: process.env.MYSQL_HOST, | ||
port: process.env.MYSQL_PORT, | ||
user: process.env.MYSQL_USER, | ||
password: process.env.MYSQL_PW, | ||
database: 'carpal', | ||
multipleStatements: true | ||
}); | ||
|
||
class DbUtils { | ||
|
||
static getConnection(){ | ||
return connection; | ||
} | ||
|
||
static query(connection, queryString) { | ||
if (typeof connection === 'string') { | ||
const db = require('./db').connection; | ||
queryString = connection; | ||
connection = db(); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
connection.query(queryString, (error, results, fields) => { | ||
if (error) { | ||
console.log("Error executing", queryString, error); | ||
} | ||
connection.end(function (err) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(results); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
} | ||
|
||
module.exports = DbUtils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let reloadDb = require("./reload-db"); | ||
reloadDb.executeAll() | ||
.catch(e => console.log(e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const DbUtils = require('./db-utils'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const changeSet = [ | ||
'2018-08-04-1-create-location-table.sql', | ||
'2018-08-04-2-create-rides-table.sql', | ||
'2018-08-04-3-create-driver-table.sql', | ||
'2018-08-04-4-create-driver_car-table.sql', | ||
'2018-08-04-5-create-driver_ride-table.sql' | ||
]; | ||
|
||
class ReloadDB { | ||
executeAll() { | ||
return Promise.all(changeSet.map(file => this.execute(file))); | ||
} | ||
|
||
execute(fileName) { | ||
let sql = fs.readFileSync(path.resolve(__dirname, './changes/' + fileName)).toString().trim(); | ||
return DbUtils.query(sql); | ||
} | ||
} | ||
|
||
module.exports = new ReloadDB(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
exports.handler = function (event, context, callback) { | ||
|
||
let AWS = require('aws-sdk'); | ||
|
||
// Create chron job | ||
// search rides with time below 24 hours | ||
// send sms to each one | ||
// update entry to say that driver was notified | ||
|
||
// create amazon account for hillscarpal | ||
|
||
sendSMS(); | ||
|
||
|
||
}; | ||
|
||
function sendSMS() { | ||
let sns = new AWS.SNS(); | ||
sns.publish({ | ||
Message: 'Hello World', | ||
PhoneNumber: '+610123456789', | ||
MessageStructure: 'text' | ||
}, function (err, data) { | ||
console.log("test2") | ||
if (err) { | ||
console.log(err.stack); | ||
} | ||
|
||
console.log('push sent'); | ||
|
||
callback(null, { | ||
"statusCode": 200, | ||
"headers": {"Date": new Date()}, | ||
"body": "" | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.