-
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.
feat(get_driver_trips): add get trips as driver
- Loading branch information
Franco Méndez
committed
Oct 24, 2019
1 parent
e62bcd4
commit 4f46198
Showing
1 changed file
with
32 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,32 @@ | ||
const aws = require('aws-sdk'); | ||
|
||
// eslint-disable-next-line import/no-absolute-path | ||
const bearerToUserId = require('/opt/nodejs/bearer_to_user_id.js'); | ||
|
||
const dynamoDB = new aws.DynamoDB.DocumentClient(); | ||
|
||
async function getTripAsDriver(userId) { | ||
const params = { | ||
TableName: process.env.dynamodb_table_name, | ||
IndexName: process.env.dynamodb_index_name, | ||
KeyConditionExpression: 'driver_id = :userId', | ||
ExpressionAttributeValues: { | ||
':userId': userId | ||
} | ||
}; | ||
const data = await dynamoDB.query(params).promise(); | ||
return data.Items; | ||
} | ||
|
||
exports.handler = async (event) => { // eslint-disable-line no-unused-vars | ||
const userId = await bearerToUserId.bearerToUserId(event.headers.Authorization.substring(7)); | ||
|
||
const trips = await getTripAsDriver(userId); | ||
|
||
const response = { | ||
statusCode: 200, | ||
headers: { 'Access-Control-Allow-Origin': '*' }, | ||
body: JSON.stringify(trips) | ||
}; | ||
return response; | ||
}; |