Skip to content

Commit

Permalink
feat(request_reservation): add validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Nov 1, 2019
1 parent f1666ee commit cf8425b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion request_reservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ exports.handler = async (event) => {
const body = JSON.parse(event.body);
const tripId = body.trip_id;
const routeObj = body.route;
const reservedSeats = body.reserved_seats || 1;
const reservedSeats = body.reserved_seats;

if (!tripId || !routeObj || !routeObj.start || !routeObj.end
|| !body.reserved_seats || !(body.reserved_seats > 0)) {
return {
statusCode: 400,
headers: { 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify({
action: 'create',
success: false,
resource: 'reservation',
message: 'Wrong or missing parameters'
})
};
}

const result = await createTripReservation(tripId, userId, reservedSeats, routeObj);

if (result) {
Expand Down

0 comments on commit cf8425b

Please sign in to comment.