controllers/AccountController.js
function(req, res, next){
      var subdomain = req.body.subdomain;

      if (!subdomain) {
        return res.json(400, 'Company subdomain is mandatory!');
      }

      AccountService
        .find({
          where: {
            subdomain: subdomain
          }
        })
        .then(function(result){
          if(result.length){
            return res.json(403, 'This URL "' + subdomain + '" is already taken');
          }
          next();
        })
        .catch(function(err){
          return res.json(500, 'There was an error: ' + err);
        });
    }
function(req, res, next){
      var subdomain = req.body.subdomain;

      if (!subdomain) {
        return res.json(400, 'Company subdomain is mandatory!');
      }

      AccountService
        .find({
          where: {
            subdomain: subdomain
          }
        })
        .then(function(result){
          if(result.length){
            return res.json(403, 'This URL "' + subdomain + '" is already taken');
          }
          next();
        })
        .catch(function(err){
          return res.json(500, 'There was an error: ' + err);
        });
    }
function ( req , res , next ) { var subdomain = req . body . subdomain ; if ( ! subdomain ) { return res . json ( 400 , 'Company subdomain is mandatory!' ) ; } AccountService . find ( { where : { subdomain : subdomain } } ) . then ( function ( result ) { if ( result . length ) { return res . json ( 403 , 'This URL "' + subdomain + '" is already taken' ) ; } next ( ) ; } ) . catch ( function ( err ) { return res . json ( 500 , 'There was an error: ' + err ) ; } ) ; }
Middleware helper function for requiring a unique subDomain for a given POST request

@param  {Request}  req  The Request Object
@param  {Response} res  The response object
@param  {Function} next Continue past this middleware
@return {void}
Middleware helper function for requiring a unique subDomain for a given POST request