Created
May 22, 2020 17:30
-
-
Save robertofrontado/0212618efd81d60f49748d9dfa44069f to your computer and use it in GitHub Desktop.
serverless-todo-updatetodo-with-service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'source-map-support/register' | |
import { APIGatewayProxyHandler, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda' | |
import TodoService from '../../services/todoService' | |
import { TodoItem } from '../../models/TodoItem' | |
export const handler: APIGatewayProxyHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => { | |
const id = event.pathParameters.id | |
const todoService = new TodoService() | |
const todo: Partial<TodoItem> = { ...JSON.parse(event.body), id } | |
const todoUpdated = await todoService.updateTodo(todo) | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ | |
item: todoUpdated | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment