-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
26 lines (23 loc) · 856 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 "./libraries/handler";
import dynamoDB from "./libraries/dynamodb";
export const main = handler(async (event, context) => {
const data = JSON.parse(event.body);
const params = {
TableName: process.env.tableName,
Key: {
userid: event.requestContext.identity.cognitoIdentityId,
noteid: event.pathParameters.id
},
// 'UpdateExpression' defines attributes.
// 'ExpressionAttributeValues' populates with values.
UpdateExpression: "SET content = :content, attachment = :attachment",
ExpressionAttributeValues: {
":attachment": data.attachment || null,
":content": data.content || null
},
// 'ReturnValues' how to return attributes, with ALL_NEW stating to return new attributes.
ReturnValues: "ALL_NEW"
};
await dynamoDB.update(params);
return { status: true };
});