Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/', function (req, res, next) {
- var tenant = new Tenant({
- name: req.body.name
- });
- var newTenant;
- tenant.save(function (err, tenant) {
- if (err) {
- return res.status(500).json({
- title: 'An error has occured',
- error: err
- });
- }
- res.status(201).json({
- message: 'Tenant created',
- obj: tenant
- });
- return(tenant._id);
- newTenant = tenant;
- });
- Tenant.findById(newTenant._id, function(err, tenant) {
- if (err) {
- return res.status(500).json({
- title:'An error occured',
- error: err
- });
- }
- var user = new User({
- email: req.body.email,
- password: bcrypt.hashSync(req.body.password, 10),
- active: req.body.active,
- tenant: tenant
- });
- user.save(function (err, user) {
- if (err) {
- return res.status(500).json({
- title: 'An error has occured',
- error: err
- });
- }
- res.status(201).json({
- message: 'User created',
- obj: user
- });
- });
- });
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement