-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45bb9f0
commit 18c468b
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const aws = require('aws-sdk'); | ||
const dynamoDB = new aws.DynamoDB.DocumentClient(); | ||
const uuidv4 = require('uuid/v4'); | ||
const moment = require('moment'); | ||
|
||
async function createTrip(carId, driverId, etd, routePoints) { | ||
let tripId = 'tri_'+uuidv4(); | ||
let createdAt = moment().format('YYYY-MM-DDTHH:mm:ss-04:00'); | ||
let params = { | ||
TableName : process.env.dynamodb_table_name, | ||
Item: { | ||
"trip_id": tripId, | ||
"car_id": carId, | ||
"driver_id": driverId, | ||
"etd": etd, | ||
"route_points": routePoints, | ||
"trip_status": "open", | ||
"created_at": createdAt | ||
} | ||
}; | ||
let data = await dynamoDB.put(params).promise(); | ||
return data; | ||
} | ||
|
||
exports.handler = async (event) => { | ||
let carId = event.car_id; | ||
let driverId = event.driver_id; | ||
let etd = event.etd; | ||
let routePoints = event.route_points; | ||
|
||
await createTrip(carId, driverId, etd, routePoints); | ||
|
||
let result = { | ||
created: true | ||
}; | ||
|
||
return result; | ||
}; |