-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.js
26 lines (23 loc) · 861 Bytes
/
update.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
import handler from "./libs/handler-lib";
import DynamoDb from "./libs/dynamodb-lib";
export const main = handler(async (event, context) => {
const data = JSON.parse(event.body);
const params = {
TableName: process.env.tableName,
// Key object below is providing partition + sort key to update
Key: {
userId: event.requestContext.identity.cognitoIdentityId,
gradeId: event.pathParameters.id,
},
//Update Expression tells dynamodb what to change
UpdateExpression: "SET content = :content, attachment = :attachment",
ExpressionAttributeValues: {
":attachment": data.attachment || null,
":content": data.content || null,
},
//Return Values param tells dynamodb whether to return new item attributes.
ReturnValues: "ALL_NEW",
};
await DynamoDb.update(params);
return { status: true };
});