Skip to content

Commit

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

interface ICreateTodo {
id: string
userId: string
title: string
done: boolean
deadline: string
}

export const handler: APIGatewayProxyHandler = async (event) => {
const { title, deadline } = JSON.parse(event.body) as ICreateTodo
const { userId } = event.pathParameters

const todo: ICreateTodo = {
id: uuid(),
userId,
title,
done: false,
deadline
}

await document.put({
TableName: 'usersTodos',
Item: todo
}).promise()

return {
statusCode: 201,
body: JSON.stringify({
message: 'Todo generated successfully!',
todo
})
}
}

0 comments on commit 5d43570

Please sign in to comment.