-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateTodo.js
More file actions
34 lines (27 loc) · 754 Bytes
/
updateTodo.js
File metadata and controls
34 lines (27 loc) · 754 Bytes
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
const { v4 } = require("uuid")
const AWS = require('aws-sdk')
const middy = require('@middy/core')
const httpJsonBodyParser = require('@middy/http-json-body-parser')
const updateTodo = async (event) => {
const dynamodb = new AWS.DynamoDB.DocumentClient()
const { completed } = event.body
const { id } = event.pathParameters
await dynamodb.update({
TableName: 'TodoTable',
Key: { id },
UpdateExpression: 'set completed = :completed',
ExpressionAttributeValues: {
':completed': completed
},
ReturnValues: "ALL_NEW"
}).promise()
return {
statusCode: 200,
body: JSON.stringify({
msg: "Todo Updated"
}),
};
};
module.exports = {
handler: middy(updateTodo).use(httpJsonBodyParser())
}