Skip to content

Instantly share code, notes, and snippets.

@robertofrontado
Last active May 22, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertofrontado/22a278dfa2bc9530c0750abcc4ed7c25 to your computer and use it in GitHub Desktop.
Save robertofrontado/22a278dfa2bc9530c0750abcc4ed7c25 to your computer and use it in GitHub Desktop.
serverless-todo-todoservice
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