From 5cdc7bae39211a62285ccdda1ed1ed5473d43400 Mon Sep 17 00:00:00 2001 From: douglas Date: Mon, 3 Sep 2018 20:01:53 +1000 Subject: [PATCH] #13 - Added endpoint to update ride --- backend/package.json | 1 + backend/src/main/rides/aws/AwsLambdaRideApis.js | 6 ++++-- backend/src/test/auth/ExpressAuthApis.js | 4 ++-- backend/src/test/expressApis.js | 14 +++++++++++--- backend/src/test/rides/express/ExpressRidesApis.js | 10 ++++++++++ doc/carpal-api.yaml | 2 +- doc/sampledata.json | 6 +++--- frontend/public/sampledata.json | 6 +++--- frontend/src/facilitator/CreateNewRide.js | 6 +++--- frontend/src/facilitator/index.js | 4 +++- 10 files changed, 41 insertions(+), 18 deletions(-) diff --git a/backend/package.json b/backend/package.json index 82729e99..53df909c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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" }, diff --git a/backend/src/main/rides/aws/AwsLambdaRideApis.js b/backend/src/main/rides/aws/AwsLambdaRideApis.js index 54f83db9..b2fa5e99 100644 --- a/backend/src/main/rides/aws/AwsLambdaRideApis.js +++ b/backend/src/main/rides/aws/AwsLambdaRideApis.js @@ -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) { @@ -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)); } diff --git a/backend/src/test/auth/ExpressAuthApis.js b/backend/src/test/auth/ExpressAuthApis.js index eabad04c..bd64c332 100644 --- a/backend/src/test/auth/ExpressAuthApis.js +++ b/backend/src/test/auth/ExpressAuthApis.js @@ -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)); } @@ -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}; } diff --git a/backend/src/test/expressApis.js b/backend/src/test/expressApis.js index cd58358a..70c0096f 100644 --- a/backend/src/test/expressApis.js +++ b/backend/src/test/expressApis.js @@ -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'); @@ -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 = { diff --git a/backend/src/test/rides/express/ExpressRidesApis.js b/backend/src/test/rides/express/ExpressRidesApis.js index 2b459994..01879698 100644 --- a/backend/src/test/rides/express/ExpressRidesApis.js +++ b/backend/src/test/rides/express/ExpressRidesApis.js @@ -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)); } @@ -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) { diff --git a/doc/carpal-api.yaml b/doc/carpal-api.yaml index d1d69ae9..3ed95ba0 100644 --- a/doc/carpal-api.yaml +++ b/doc/carpal-api.yaml @@ -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: diff --git a/doc/sampledata.json b/doc/sampledata.json index 7140af8b..17d20e24 100644 --- a/doc/sampledata.json +++ b/doc/sampledata.json @@ -65,7 +65,7 @@ "fbLink": "www.facebook.com/events/965341583633198", "driverGender": "Female", "carType": "SUV", - "status": "Closed", + "status": "Ended", "facilitatorId": 1 }, { @@ -111,7 +111,7 @@ "fbLink": "www.facebook.com/events/965341583633198", "driverGender": "All", "carType": "SUV", - "status": "Closed", + "status": "Ended", "facilitatorId": 2 }, { @@ -180,7 +180,7 @@ "fbLink": "www.facebook.com/events/965341583633198", "driverGender": "All", "carType": "Normal", - "status": "Closed", + "status": "Ended", "facilitatorId": 3 }, { diff --git a/frontend/public/sampledata.json b/frontend/public/sampledata.json index 7140af8b..17d20e24 100644 --- a/frontend/public/sampledata.json +++ b/frontend/public/sampledata.json @@ -65,7 +65,7 @@ "fbLink": "www.facebook.com/events/965341583633198", "driverGender": "Female", "carType": "SUV", - "status": "Closed", + "status": "Ended", "facilitatorId": 1 }, { @@ -111,7 +111,7 @@ "fbLink": "www.facebook.com/events/965341583633198", "driverGender": "All", "carType": "SUV", - "status": "Closed", + "status": "Ended", "facilitatorId": 2 }, { @@ -180,7 +180,7 @@ "fbLink": "www.facebook.com/events/965341583633198", "driverGender": "All", "carType": "Normal", - "status": "Closed", + "status": "Ended", "facilitatorId": 3 }, { diff --git a/frontend/src/facilitator/CreateNewRide.js b/frontend/src/facilitator/CreateNewRide.js index 26132224..76de8a1c 100644 --- a/frontend/src/facilitator/CreateNewRide.js +++ b/frontend/src/facilitator/CreateNewRide.js @@ -37,7 +37,7 @@ class CreateNewRide extends Component { }, }) .then(res => { - const data = res.data[0]; + const data = res.data; this.setState(data); }); @@ -102,8 +102,8 @@ class CreateNewRide extends Component { this.setState({ pickupTimeAndDateInUTC: date })} showTimeSelect timeFormat="HH:mm" diff --git a/frontend/src/facilitator/index.js b/frontend/src/facilitator/index.js index e8e247e6..47f54324 100644 --- a/frontend/src/facilitator/index.js +++ b/frontend/src/facilitator/index.js @@ -93,7 +93,9 @@ const columns = [ className="custom-select" > - + + + ),