Last active
May 22, 2020 17:16
-
-
Save robertofrontado/22a278dfa2bc9530c0750abcc4ed7c25 to your computer and use it in GitHub Desktop.
serverless-todo-todoservice
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 * as uuid from 'uuid' | |
import TodoRepository from '../repositories/TodoRepository' | |
import { TodoItem } from '../models/TodoItem' | |
export default class TodoService { | |
todoRepository: TodoRepository; | |
constructor(todoRepository: TodoRepository = new TodoRepository()) { | |
this.todoRepository = todoRepository | |
} | |
async getAllTodos(): Promise<TodoItem[]> { | |
return this.todoRepository.getAllTodos() | |
} | |
async createTodo(name: string): Promise<TodoItem> { | |
const id = uuid.v4() | |
return await this.todoRepository.createTodo({ | |
id, | |
name, | |
done: false, | |
createdAt: new Date().toISOString() | |
}) | |
} | |
async updateTodo(partialTodo: Partial<TodoItem>) { | |
return await this.todoRepository.updateTodo(partialTodo) | |
} | |
async deleteTodoById(id: string) { | |
return await this.todoRepository.deleteTodoById(id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment