lib/definitions/command.js
function (cmd, aggregateModel, callback) {
    if (this.existing === true && aggregateModel.get('_revision') === 0) {
      var err = new BusinessRuleError('This command only wants to be handled, if aggregate already existing!', {
        type: 'AggregateNotExisting',
        aggregateId: aggregateModel.id,
        aggregateRevision: aggregateModel.get('_revision')
      });
      debug(err);
      return callback(err);
    }

    if (this.existing === false && aggregateModel.get('_revision') !== 0) {
      var err = new BusinessRuleError('This command only wants to be handled, if aggregate not existing!', {
        type: 'AggregateAlreadyExisting',
        aggregateId: aggregateModel.id,
        aggregateRevision: aggregateModel.get('_revision')
      });
      debug(err);
      return callback(err);
    }

    if (this.preConditions.length === 0) {
      debug('no pre-condition for ' + this.name);
      return callback(null);
    }

    var self = this;
    async.eachSeries(this.preConditions, function (preCondition, callback) {
      if (preCondition.version === undefined || preCondition.version === null || preCondition.version === self.version) {
        return preCondition.check(cmd, aggregateModel, callback);
      }
      callback(null);
    }, callback);
  }
function (cmd, aggregateModel, callback) {
    if (this.existing === true && aggregateModel.get('_revision') === 0) {
      var err = new BusinessRuleError('This command only wants to be handled, if aggregate already existing!', {
        type: 'AggregateNotExisting',
        aggregateId: aggregateModel.id,
        aggregateRevision: aggregateModel.get('_revision')
      });
      debug(err);
      return callback(err);
    }

    if (this.existing === false && aggregateModel.get('_revision') !== 0) {
      var err = new BusinessRuleError('This command only wants to be handled, if aggregate not existing!', {
        type: 'AggregateAlreadyExisting',
        aggregateId: aggregateModel.id,
        aggregateRevision: aggregateModel.get('_revision')
      });
      debug(err);
      return callback(err);
    }

    if (this.preConditions.length === 0) {
      debug('no pre-condition for ' + this.name);
      return callback(null);
    }

    var self = this;
    async.eachSeries(this.preConditions, function (preCondition, callback) {
      if (preCondition.version === undefined || preCondition.version === null || preCondition.version === self.version) {
        return preCondition.check(cmd, aggregateModel, callback);
      }
      callback(null);
    }, callback);
  }
function ( cmd , aggregateModel , callback ) { if ( this . existing === true && aggregateModel . get ( '_revision' ) === 0 ) { var err = new BusinessRuleError ( 'This command only wants to be handled, if aggregate already existing!' , { type : 'AggregateNotExisting' , aggregateId : aggregateModel . id , aggregateRevision : aggregateModel . get ( '_revision' ) } ) ; debug ( err ) ; return callback ( err ) ; } if ( this . existing === false && aggregateModel . get ( '_revision' ) !== 0 ) { var err = new BusinessRuleError ( 'This command only wants to be handled, if aggregate not existing!' , { type : 'AggregateAlreadyExisting' , aggregateId : aggregateModel . id , aggregateRevision : aggregateModel . get ( '_revision' ) } ) ; debug ( err ) ; return callback ( err ) ; } if ( this . preConditions . length === 0 ) { debug ( 'no pre-condition for ' + this . name ) ; return callback ( null ) ; } var self = this ; async . eachSeries ( this . preConditions , function ( preCondition , callback ) { if ( preCondition . version === undefined || preCondition . version === null || preCondition . version === self . version ) { return preCondition . check ( cmd , aggregateModel , callback ) ; } callback ( null ) ; } , callback ) ; }
Checks for pre-conditions
@param {Object}         cmd            The command object.
@param {AggregateModel} aggregateModel The aggregate object.
@param {Function}       callback       The function, that will be called when this action is completed.
`function(err){}`
Checks for pre - conditions