Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. var query = {
  2. where: {
  3. id: req.params.id
  4. },
  5. include: defaultIncludes()
  6. }
  7. models.products.findOne(query)
  8. .then(function (product) {
  9. if (!product) {
  10. return res.status(404).json({message: 'Product not found' });
  11. } else {
  12. this.product = product;
  13. return models.services.findById(req.body.service_id);
  14. }
  15. })
  16. .then(function (service) {
  17. return this.product.addServices(service);
  18. })
  19. .then(function (result) {
  20. return this.product.save();
  21. // return models.products.findOne(query);
  22. })
  23. .then(function (product) {
  24. return res.status(200).json(product)
  25. })
  26. .catch(function (err) {
  27. logger.error(err);
  28. return res.status(500).json({error: err.message});
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement