api/models/User.js
/**
     * beforeUpdate
     * @description Before updating a user with possibly changed userType, find or create the associated
     *              model if it doesn't exist yet
     */
beforeUpdate
@description Before updating a user with possibly changed userType, find or create the associated
model if it doesn't exist yet
beforeUpdate @description Before updating a user with possibly changed userType find or create the associated model if it doesn ' t exist yet
function updateUserType(values, cb) {
      if (values.userType && sails.models[values.userType]) {
        return User.findOne({ username: values.username })
          .then(function (user) {
            return (user.userType !== values.userType) ? sails.models[values.userType].findOrCreate({person: user.person}, {person: user.person}) : null;
          })
          .then(function (userType) {
            return cb();
          })
          .catch(function (err) {
            return cb(err);
          });
      } else {
        cb();
      }
    }
function updateUserType ( values , cb ) { if ( values . userType && sails . models [ values . userType ] ) { return User . findOne ( { username : values . username } ) . then ( function ( user ) { return ( user . userType !== values . userType ) ? sails . models [ values . userType ] . findOrCreate ( { person : user . person } , { person : user . person } ) : null ; } ) . then ( function ( userType ) { return cb ( ) ; } ) . catch ( function ( err ) { return cb ( err ) ; } ) ; } else { cb ( ) ; } }
beforeUpdate
 @description Before updating a user with possibly changed userType, find or create the associated
              model if it doesn't exist yet
beforeUpdate @description Before updating a user with possibly changed userType find or create the associated model if it doesn ' t exist yet