Skip to content

Commit

Permalink
#13 - Added endpoint to update ride
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascvas committed Sep 3, 2018
1 parent 9756daf commit 5cdc7ba
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"scripts": {
"test": "mocha './src/test/**/*.test.js'",
"start": "node src/test/expressApis.js",
"refresh-db": "node ./src/main/database/index.js",
"refresh-test-db": "node ./src/test/database/refreshDatabase.js"
},
Expand Down
6 changes: 4 additions & 2 deletions backend/src/main/rides/aws/AwsLambdaRideApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const decodeJwt = require('../../utils/jwt').decodeJwt;
class AwsLambdaRideApis {
constructor(createRideService,
listRidesService,
findOneRideService) {
findOneRideService,
updateRideService) {
this.createRideService = createRideService;
this.listRidesService = listRidesService;
this.findOneRideService = findOneRideService;
this.updateRideService = updateRideService;
}

create(event, context, callback) {
Expand All @@ -20,7 +22,7 @@ class AwsLambdaRideApis {
const loginData = decodeJwt(event);
const ride = JSON.parse(event.body);
const id = event.pathParameters.id;
return this.createRideService.updateRide(id, ride, loginData)
return this.updateRideService.updateRide(id, ride, loginData)
.then(result => callback(null, result))
.catch(result => callback(result));
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/test/auth/ExpressAuthApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExpressAuthApis {
wellKnown(req, res) {
let expiry = moment().add(100, 'd');
console.log(req.query);
let jwks = fs.readFileSync(path.resolve(__dirname, '../../config/express/certs/jwks.json'));
let jwks = fs.readFileSync(path.resolve(__dirname, '../config/express/certs/jwks.json'));
res.status(200).send(JSON.parse(jwks));
}

Expand Down Expand Up @@ -62,7 +62,7 @@ class ExpressAuthApis {
let payload = this._completeJWT(userInfo, host, expiry.toDate(), queryParams.nonce);

let accessToken = userInfo.role;
let cert = fs.readFileSync(path.resolve(__dirname, '../../config/express/certs/private.key'));
let cert = fs.readFileSync(path.resolve(__dirname, '../config/express/certs/private.key'));
let jwtToken = jwt.sign(payload, cert, {algorithm: 'RS256'});
return {accessToken, jwtToken};
}
Expand Down
14 changes: 11 additions & 3 deletions backend/src/test/expressApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const path = require('path');
const CreateRideService = require('../main/rides/CreateRideService');
const ListRidesService = require('../main/rides/ListRidesService');
const FindOneRideService = require('../main/rides/FindOneRideService');
const UpdateRideService = require('../main/rides/UpdateRideService');
const DatabaseManager = require('../main/database/DatabaseManager');
const ExpressRideApis = require('./rides/express/ExpressRidesApis');
const ExpressAuthApis = require('./auth/ExpressAuthApis');
const databaseConfig = require('./database/databaseTestConfig');
const AwsLambdaRideApis = require('../main/rides/aws/AwsLambdaRideApis');
const bodyParser = require('body-parser');
const databaseManager = new DatabaseManager();
const databaseManager = new DatabaseManager(databaseConfig);

const https = require('https');
const http = require('http');
Expand All @@ -23,18 +25,24 @@ process.env.DOMAIN = 'localhost:8081';
const createRideService = new CreateRideService(databaseManager);
const listRidesService = new ListRidesService(databaseManager);
const findOneRideService = new FindOneRideService(databaseManager);
const updateRideService = new UpdateRideService(databaseManager);
const app = express();
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded

app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Origin", req.get("Origin"));
res.header("Access-Control-Allow-Headers", "*");
res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE");
next();
});

new ExpressAuthApis(app);
let awsLambdaRideApis = new AwsLambdaRideApis(createRideService, listRidesService, findOneRideService);
let awsLambdaRideApis = new AwsLambdaRideApis(createRideService,
listRidesService,
findOneRideService,
updateRideService);

new ExpressRideApis(app, awsLambdaRideApis);

const options = {
Expand Down
10 changes: 10 additions & 0 deletions backend/src/test/rides/express/ExpressRidesApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class ExpressRideApis {
this.app = app;
this.awsLambdaRideApis = awsLambdaRideApis;
this.app.post('/rides', this.create.bind(this));
this.app.put('/rides/:id', this.update.bind(this));
this.app.get('/rides/:id', this.findOne.bind(this));
this.app.get('/rides', this.list.bind(this));
}
Expand All @@ -16,6 +17,15 @@ class ExpressRideApis {
});
}

update(req, res) {
this.awsLambdaRideApis.update(this._extractAwsEvent(req), {}, (error, result) => {
if (error) {
return res.status(500).send(error);
}
res.status(200).send(result);
});
}

list(req, res) {
this.awsLambdaRideApis.list(this._extractAwsEvent(req), {}, (error, result) => {
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion doc/carpal-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ components:
type: string
status:
type: string
description: Can be Open / Closed
description: Can be Open / Confirmed / Canceled / Ended
Location:
properties:
latitude:
Expand Down
6 changes: 3 additions & 3 deletions doc/sampledata.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"fbLink": "www.facebook.com/events/965341583633198",
"driverGender": "Female",
"carType": "SUV",
"status": "Closed",
"status": "Ended",
"facilitatorId": 1
},
{
Expand Down Expand Up @@ -111,7 +111,7 @@
"fbLink": "www.facebook.com/events/965341583633198",
"driverGender": "All",
"carType": "SUV",
"status": "Closed",
"status": "Ended",
"facilitatorId": 2
},
{
Expand Down Expand Up @@ -180,7 +180,7 @@
"fbLink": "www.facebook.com/events/965341583633198",
"driverGender": "All",
"carType": "Normal",
"status": "Closed",
"status": "Ended",
"facilitatorId": 3
},
{
Expand Down
6 changes: 3 additions & 3 deletions frontend/public/sampledata.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"fbLink": "www.facebook.com/events/965341583633198",
"driverGender": "Female",
"carType": "SUV",
"status": "Closed",
"status": "Ended",
"facilitatorId": 1
},
{
Expand Down Expand Up @@ -111,7 +111,7 @@
"fbLink": "www.facebook.com/events/965341583633198",
"driverGender": "All",
"carType": "SUV",
"status": "Closed",
"status": "Ended",
"facilitatorId": 2
},
{
Expand Down Expand Up @@ -180,7 +180,7 @@
"fbLink": "www.facebook.com/events/965341583633198",
"driverGender": "All",
"carType": "Normal",
"status": "Closed",
"status": "Ended",
"facilitatorId": 3
},
{
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/facilitator/CreateNewRide.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CreateNewRide extends Component {
},
})
.then(res => {
const data = res.data[0];
const data = res.data;

this.setState(data);
});
Expand Down Expand Up @@ -102,8 +102,8 @@ class CreateNewRide extends Component {
<label>Date</label>
<DatePicker
required
value={this.state.pickupTimeAndDateInUTC}
selected={this.state.pickupTimeAndDateInUTC}
value={moment(this.state.pickupTimeAndDateInUTC || Date.now())}
selected={moment(this.state.pickupTimeAndDateInUTC || Date.now())}
onChange={date => this.setState({ pickupTimeAndDateInUTC: date })}
showTimeSelect
timeFormat="HH:mm"
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/facilitator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const columns = [
className="custom-select"
>
<option value="OPEN">Open</option>
<option value="CLOSED">Closed</option>
<option value="CONFIRMED">Confirmed</option>
<option value="ENDED">Ended</option>
<option value="CANCELED">Canceled</option>
</select>
</div>
),
Expand Down

0 comments on commit 5cdc7ba

Please sign in to comment.