Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't put .then inside a .then #36

Open
neugierige opened this issue Dec 12, 2016 · 4 comments
Open

Don't put .then inside a .then #36

neugierige opened this issue Dec 12, 2016 · 4 comments

Comments

@neugierige
Copy link

neugierige commented Dec 12, 2016

const update = (req, res, next) => {
  let search = { _id: req.params.id, _owner: req.currentUser._id };
  Example.findOne(search)
    .then(example => {
      if (!example) {
        return next();
      }
      delete req.body._owner;  // disallow owner reassignment.
      return example.update(req.body.example)
        .then(() => res.sendStatus(200));
    })
    .catch(err => next(err));
};

should be updated to:

const update = (req, res, next) => {
  let search = { _id: req.params.id, _owner: req.currentUser._id };
  Example.findOne(search)
    .then(example => {
      if (!example) {
        return next();
      }
      delete req.body._owner;  // disallow owner reassignment.
      return example.update(req.body.example);
    })
    .then(() => res.sendStatus(200))
    .catch(err => next(err));
};

@raq929

@neugierige
Copy link
Author

also appears in const destroy

@gaand
Copy link

gaand commented Dec 13, 2016

I believe this refactoring contains a bug. Both next and res.sendStatus will run if example is falsy.

@raq929
Copy link

raq929 commented Dec 14, 2016 via email

@raq929
Copy link

raq929 commented Mar 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants