-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_user.js
57 lines (51 loc) · 1.51 KB
/
get_user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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.selfie_image, user_verifications'
};
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: {
email: result.user_verifications.email,
phone: result.user_verifications.phone,
identity:
result.user_verifications.identification.front
&& result.user_verifications.identification.back,
driver_license:
result.user_verifications.driver_license.front
&& result.user_verifications.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)
};
};