Exemplo n.º 1
0
app.put('/authors/:id', function (req, res) {
  var newFields = req.body;
  var authorId = newFields._id;
  //TODO: validation if ID missing
  var authorToUpdate = _.findwhere(AUTHORS, {_id: authorId});
  var newAuthor = _.extend(authorToUpdate, newFields);
  AUTHORS = _.map(AUTHORS, function(author) {
    return newAuthor._id === newAuthor._id ?
      newAuthor :
      author;
  });

  res.send(newAuthor);
});
Exemplo n.º 2
0
app.put('/books/:id', function (req, res) {
  var newFields = req.body;
  var bookId = newFields._id;
  //TODO: validation if ID missing
  var bookToUpdate = _.findwhere(BOOKS, {_id: bookId});
  var newBook = _.extend(bookToUpdate, newFields);
  BOOKS = _.map(BOOKS, function(book) {
    return book._id === newBook._id ?
      newBook :
      book;
  });

  res.send(newBook);
});