Skip to content

Commit

Permalink
fix(get_user): adapt to new user images structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Oct 27, 2019
1 parent ec010d6 commit b3467d5
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions get_user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const aws = require('aws-sdk');

const dynamoDB = new aws.DynamoDB.DocumentClient();

const UsersTableName = process.env.dynamodb_users_table_name;

async function getUser(userId) {
const params = {
TableName: UsersTableName,
Key: {
user_id: userId
},
ProjectionExpression: 'user_id, first_name, last_name, phone, user_identifications'
};
const data = await dynamoDB.get(params).promise();
return data.Item;
}

function parseBody(result) {
return {
user_id: result.user_id,
first_name: result.first_name,
last_name: result.last_name,
avatar: result.user_identifications.selfie_image,
user_verifications: {
phone: !!result.phone,
identity:
!!result.user_identifications.identification.front
&& !!result.user_identifications.identification.back,
driver_license:
!!result.user_identifications.driver_license.front
&& !!result.user_identifications.driver_license.back
}
};
}

exports.handler = async (event) => {
const userId = event.pathParameters.user;
const result = await getUser(userId);
if (result) {
return {
statusCode: 200,
headers: { 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify(parseBody(result))
};
}

const responseBody = {
message: 'User does not exist'
};
return {
statusCode: 422,
headers: { 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify(responseBody)
};
};

0 comments on commit b3467d5

Please sign in to comment.