UNPKG

create-node-mongo-express-app

Version:

Node Js Template with MVC pattern, typescript, mongoose and express

28 lines (21 loc) 619 B
import { Todo } from '../@types/Todo'; import { TodoModel } from '../models/todo.model'; class TodoService { async getAllTodos() { return await TodoModel.find(); } async getTodoById(id: string) { return await TodoModel.findById(id); } async createTodo(todo: Todo) { return await TodoModel.create(todo); } async updateTodo(id: string, todo: Todo) { return await TodoModel.findByIdAndUpdate(id, todo); } async deleteTodo(id: string) { return await TodoModel.findByIdAndDelete(id); } } const todoService = new TodoService(); export { todoService };