Skip to content

Commit

Permalink
Add function to get the todo for the specified user
Browse files Browse the repository at this point in the history
  • Loading branch information
Neto1904 committed Jan 30, 2022
1 parent 5d43570 commit ae408c6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/functions/getUserTodo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { APIGatewayProxyHandler } from "aws-lambda"
import { document } from '../utils/dynamodbClient'

export const handler: APIGatewayProxyHandler = async (event) => {
const { userId } = event.pathParameters

const response = await document
.query({
TableName: 'usersTodos',
KeyConditionExpression: 'userId = :userId',
ExpressionAttributeValues: {
':userId': userId
}
}).promise()

if(response.Items.length === 0) {
return {
statusCode: 201,
body: JSON.stringify({
message: 'No todos found for specified user!'
})
}
}

return {
statusCode: 201,
body: JSON.stringify({
todos: response.Items
})
}
}

0 comments on commit ae408c6

Please sign in to comment.