function seed(doc, options) {
  var User = mongoose.model('User');

  return new Promise(function (resolve, reject) {

    skipDocument()
      .then(add)
      .then(function (response) {
        return resolve(response);
      })
      .catch(function (err) {
        return reject(err);
      });

    function skipDocument() {
      return new Promise(function (resolve, reject) {
        User.findOne({ username: doc.username }).exec(function (err, user) {
          if (err) return reject(err);
          if (!user) return resolve(false);
          if (user && !options.overwrite) return resolve(true);

          // Remove User (overwrite)
          user.remove(function (err) {
            if (err) return reject(err);
            return resolve(false);
          });
        });
      });
    }

    function add(skip) {
      return new Promise(function (resolve, reject) {
        if (skip)
          return resolve({ message: chalk.yellow('アカウント情報作成: User\t\t' + doc.username + ' skipped') });

        User.generateRandomPassphrase()
          .then(function (passphrase) {
            var user = new User(doc);
            user.password = passphrase;
            user.save(function (err) {
              if (err) return reject(err);
              return resolve({ message: 'ログインID： ' + user.username + ' ・パスワード： ' + passphrase });
            });
          })
          .catch(function (err) { return reject(err); });
      });
    }

  });
}
/**
* Seeds the User collection with document (User)
* and provided options.
*/
Seeds the User collection with document (User)
and provided options.
Seeds the User collection with document ( User ) and provided options .
function seed(doc, options) {
  var User = mongoose.model('User');
  return new Promise(function (resolve, reject) {
    skipDocument()
      .then(add)
      .then(function (response) {
        return resolve(response);
      })
      .catch(function (err) {
        return reject(err);
      });
    function skipDocument() {
      return new Promise(function (resolve, reject) {
        User.findOne({ username: doc.username }).exec(function (err, user) {
          if (err) return reject(err);
          if (!user) return resolve(false);
          if (user && !options.overwrite) return resolve(true);
          user.remove(function (err) {
            if (err) return reject(err);
            return resolve(false);
          });
        });
      });
    }
    function add(skip) {
      return new Promise(function (resolve, reject) {
        if (skip)
          return resolve({ message: chalk.yellow('アカウント情報作成: User\t\t' + doc.username + ' skipped') });
        User.generateRandomPassphrase()
          .then(function (passphrase) {
            var user = new User(doc);
            user.password = passphrase;
            user.save(function (err) {
              if (err) return reject(err);
              return resolve({ message: 'ログインID： ' + user.username + ' ・パスワード： ' + passphrase });
            });
          })
          .catch(function (err) { return reject(err); });
      });
    }
  });
}
function seed ( doc , options ) { var User = mongoose . model ( 'User' ) ; return new Promise ( function ( resolve , reject ) { skipDocument ( ) . then ( add ) . then ( function ( response ) { return resolve ( response ) ; } ) . catch ( function ( err ) { return reject ( err ) ; } ) ; function skipDocument ( ) { return new Promise ( function ( resolve , reject ) { User . findOne ( { username : doc . username } ) . exec ( function ( err , user ) { if ( err ) return reject ( err ) ; if ( ! user ) return resolve ( false ) ; if ( user && ! options . overwrite ) return resolve ( true ) ; user . remove ( function ( err ) { if ( err ) return reject ( err ) ; return resolve ( false ) ; } ) ; } ) ; } ) ; } function add ( skip ) { return new Promise ( function ( resolve , reject ) { if ( skip ) return resolve ( { message : chalk . yellow ( 'アカウント情報作成: User\t\t' + doc.username +  kip p ed') }); User . generateRandomPassphrase ( ) . then ( function ( passphrase ) { var user = new User ( doc ) ; user . password = passphrase ; user . save ( function ( err ) { if ( err ) return reject ( err ) ; return resolve ( { message : 'ログインID： ' + user.us r ame  +  ' ・パスワー ： ' + passphrase }); } ) ; } ) . catch ( function ( err ) { return reject ( err ) ; } ) ; } ) ; } } ) ; }
Seeds the User collection with document (User)
and provided options.
Seeds the User collection with document ( User ) and provided options .
// Remove User (overwrite)