-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.js
39 lines (36 loc) · 1.16 KB
/
list.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
import * as dynamoDbLib from "./libs/dynamodb-lib";
import { success, failure } from "./libs/response-lib";
const TABLE_NAME = process.env.DATABASE_NAME
export async function main(event, context) {
console.log("List",event)
let params
if (event.queryStringParameters && event.queryStringParameters.domain) {
params = {
TableName:TABLE_NAME,
KeyConditionExpression: "userId = :userId AND begins_with(settingName,:domain)",
ExpressionAttributeValues: {
":userId": event.requestContext.authorizer.principalId,
":domain": event.queryStringParameters.domain
}
}
} else {
params = {
TableName:TABLE_NAME,
KeyConditionExpression: "userId = :userId",
ExpressionAttributeValues: {
":userId": event.requestContext.authorizer.principalId
}
}
}
try {
const result = await dynamoDbLib.call("query", params);
// Return the matching list of items in response body
return success(result.Items.reduce(function(acc,cur,i) {
acc[cur.settingName] = cur.content
return acc
},{}))
} catch (e) {
console.log(e)
return failure({ status: false });
}
}