Updating API endpoints

Let us update the routes/index.js file with the new logic for working with our todos:

// routes/index.jsconst express = require('express');const router = express.Router();// require diskdbconst db = require('diskdb');db.connect(__dirname, ['todos']);// store Todorouter.post('/todo', function(req, res, next) {var todo = req.body;if (!todo.action || !(todo.isDone + '')) {res.status(400);res.json({error: 'bad data'});} else {db.todos.save(todo);res.json(todo);}});// get Todosrouter.get('/todos', function(req, res, next) {const todos = db.todos.find();res.json(todos);});// update Todorouter.put('/todo/:id', function(req, res, next) {const todo = req.body;db.todos.update({_id: req.params.id}, todo);res.json({ msg: `${req.params.id} ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.