Skip to content

Commit

Permalink
feat(get_driver_trips): add get trips as driver
Browse files Browse the repository at this point in the history
  • 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.
32 changes: 32 additions & 0 deletions get_driver_trips.js
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;
};

0 comments on commit 4f46198

Please sign in to comment.