Skip to content

Commit

Permalink
feat(create_driver_trip): force required parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Oct 31, 2019
1 parent 3a6d1d5 commit ce17c72
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions create_driver_trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const moment = require('moment');

const dynamoDB = new aws.DynamoDB.DocumentClient();

function isEmpty(obj) {
return Object.keys(obj).length === 0 && obj.constructor === Object;
}

async function createTrip(driverId, vehicleId, availableSeats, etdInfo, routePoints) {
const tripId = `tri_${uuidv4()}`;
const timestamp = moment().format('YYYY-MM-DDTHH:mm:ss-04:00');
Expand Down Expand Up @@ -34,6 +38,22 @@ exports.handler = async (event) => {
const vehicleId = body.vehicle_id;
const availableSeats = body.available_seats;

if (
!etdInfo || isEmpty(etdInfo) || !routePoints || !(routePoints.length > 0)
|| !vehicleId || !(availableSeats > 0)
) {
return {
statusCode: 400,
headers: { 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify({
action: 'create',
success: false,
resource: 'trip',
message: 'Wrong or missing parameters'
})
};
}

const [tripId, timestamp] = await createTrip(
userId, vehicleId, availableSeats, etdInfo, routePoints
);
Expand Down

0 comments on commit ce17c72

Please sign in to comment.