Skip to content

Commit

Permalink
feat(accept_reservation): add updated at timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Oct 25, 2019
1 parent 67396b5 commit 6a2a63c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions accept_reservation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const aws = require('aws-sdk');
const moment = require('moment');

const ReservationsTableName = process.env.dynamodb_reservations_table_name;
const TripsTableName = process.env.dynamodb_trips_table_name;
Expand All @@ -19,6 +20,7 @@ async function getReservedSeats(reservationId) {

async function acceptReservation(reservedSeats, reservationId, tripId) {
const updatedStatus = 'accepted';
const timestamp = moment().format('YYYY-MM-DDTHH:mm:ss-04:00');
try {
await dynamoDB
.transactWrite({
Expand All @@ -43,9 +45,10 @@ async function acceptReservation(reservedSeats, reservationId, tripId) {
},
ConditionExpression: 'available_seats >= :reserved_seats',
UpdateExpression:
'set available_seats = available_seats - :reserved_seats',
'set available_seats = available_seats - :reserved_seats, updated_at = :now',
ExpressionAttributeValues: {
':reserved_seats': reservedSeats
':reserved_seats': reservedSeats,
':now': timestamp
}
}
}
Expand Down

0 comments on commit 6a2a63c

Please sign in to comment.