Advertisement
Guest User

Untitled

a guest
Aug 27th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. router.post('/', function (req, res, next) {
  2.  
  3. var tenant = new Tenant({
  4. name: req.body.name
  5. });
  6. var newTenant;
  7.  
  8. tenant.save(function (err, tenant) {
  9. if (err) {
  10. return res.status(500).json({
  11. title: 'An error has occured',
  12. error: err
  13. });
  14. }
  15. res.status(201).json({
  16. message: 'Tenant created',
  17. obj: tenant
  18. });
  19. return(tenant._id);
  20. newTenant = tenant;
  21. });
  22.  
  23. Tenant.findById(newTenant._id, function(err, tenant) {
  24. if (err) {
  25. return res.status(500).json({
  26. title:'An error occured',
  27. error: err
  28. });
  29. }
  30. var user = new User({
  31. email: req.body.email,
  32. password: bcrypt.hashSync(req.body.password, 10),
  33. active: req.body.active,
  34. tenant: tenant
  35. });
  36. user.save(function (err, user) {
  37. if (err) {
  38. return res.status(500).json({
  39. title: 'An error has occured',
  40. error: err
  41. });
  42. }
  43. res.status(201).json({
  44. message: 'User created',
  45. obj: user
  46. });
  47. });
  48. });
  49.  
  50. });
  51.  
  52. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement