angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

PUT doesn't work after updating to latest mongoose and lodash #1706

Closed Abdizriel closed 8 years ago

Abdizriel commented 8 years ago

Hi,

When I updated:

PUT/PATCH endpoints doesn't work for me. I have tried to change _.merge to following:

and I have got following error: [TypeError: expecting an array or an iterable object but got [object Null]]

Do you have any idea how I can solve that?

Abdizriel commented 8 years ago

Hello @Awk34

That's my dependencies list:

    "express": "^4.13.3",
    "morgan": "~1.7.0",
    "body-parser": "^1.13.3",
    "method-override": "^2.3.5",
    "cookie-parser": "^1.3.5",
    "express-session": "^1.11.3",
    "errorhandler": "^1.4.2",
    "compression": "^1.5.2",
    "composable-middleware": "^0.3.0",
    "lodash": "^4.6.1",
    "lusca": "^1.3.0",
    "babel-runtime": "^5.8.20",
    "ejs": "^2.3.3",
    "mongoose": "^4.1.2",
    "bluebird": "^3.3.3",
    "connect-mongo": "^1.1.0",
    "jsonwebtoken": "^5.0.0",
    "express-jwt": "^3.0.0",
    "passport": "~0.3.0",
    "passport-local": "^1.0.0",
    "passport-facebook": "^2.0.0",
    "passport-google-oauth": "~1.0.0",
    "socket.io": "^1.3.5",
    "socket.io-client": "^1.3.5",
    "socketio-jwt": "^4.2.0",
    "serve-favicon": "^2.3.0"

I have only updated dependencies. Code for PUT(update) is the same as generated one:

export function update(req, res) {
  if (req.body._id) {
    delete req.body._id;
  }
  Kennel.findByIdAsync(req.params.id)
    .then(handleEntityNotFound(res))
    .then(saveUpdates(req.body))
    .then(respondWithResult(res))
    .catch(handleError(res));
}

And that is function that returns following error: [TypeError: expecting an array or an iterable object but got [object Null]]

function saveUpdates(updates) {
  return function(entity) {
    var updated = _.assignIn(entity, updates);

    return updated.saveAsync()
      .spread(updated => {
        return updated;
      });
  };
}

The issue could be checked in following repository: DOGZ

Awk34 commented 8 years ago

I think this has been fixed with the Mongoose 4 update in the generator