lib/defaultCommandHandler.js
function (aggregate, cmd) {
    if (!aggregate || !_.isObject(aggregate)) {
      var err = new Error('Please pass a valid aggregate!');
      debug(err);
      throw err;
    }
    if (!cmd || !_.isObject(cmd)) {
      var err = new Error('Please pass a valid command!');
      debug(err);
      throw err;
    }

    var contextName, aggregateName, aggregateId;

    if (!!this.definitions.command.context) {
      contextName = dotty.get(cmd, this.definitions.command.context);
    }

    if (!!this.definitions.command.aggregate) {
      aggregateName = dotty.get(cmd, this.definitions.command.aggregate);
    }

    if (!!this.definitions.command.aggregateId) {
      aggregateId = dotty.get(cmd, this.definitions.command.aggregateId);
    }

    var streamInfo = {
      context: contextName,
      aggregate: aggregateName,
      aggregateId: aggregateId
    };

    if (aggregate.isDestroyed()) {
      return new AggregateDestroyedError('Aggregate has already been destroyed!', {
        aggregateId: aggregate.id,
        aggregateRevision: aggregate.getRevision(streamInfo)
      });
    }

    return null;
  }
function (aggregate, cmd) {
    if (!aggregate || !_.isObject(aggregate)) {
      var err = new Error('Please pass a valid aggregate!');
      debug(err);
      throw err;
    }
    if (!cmd || !_.isObject(cmd)) {
      var err = new Error('Please pass a valid command!');
      debug(err);
      throw err;
    }

    var contextName, aggregateName, aggregateId;

    if (!!this.definitions.command.context) {
      contextName = dotty.get(cmd, this.definitions.command.context);
    }

    if (!!this.definitions.command.aggregate) {
      aggregateName = dotty.get(cmd, this.definitions.command.aggregate);
    }

    if (!!this.definitions.command.aggregateId) {
      aggregateId = dotty.get(cmd, this.definitions.command.aggregateId);
    }

    var streamInfo = {
      context: contextName,
      aggregate: aggregateName,
      aggregateId: aggregateId
    };

    if (aggregate.isDestroyed()) {
      return new AggregateDestroyedError('Aggregate has already been destroyed!', {
        aggregateId: aggregate.id,
        aggregateRevision: aggregate.getRevision(streamInfo)
      });
    }

    return null;
  }
function ( aggregate , cmd ) { if ( ! aggregate || ! _ . isObject ( aggregate ) ) { var err = new Error ( 'Please pass a valid aggregate!' ) ; debug ( err ) ; throw err ; } if ( ! cmd || ! _ . isObject ( cmd ) ) { var err = new Error ( 'Please pass a valid command!' ) ; debug ( err ) ; throw err ; } var contextName , aggregateName , aggregateId ; if ( ! ! this . definitions . command . context ) { contextName = dotty . get ( cmd , this . definitions . command . context ) ; } if ( ! ! this . definitions . command . aggregate ) { aggregateName = dotty . get ( cmd , this . definitions . command . aggregate ) ; } if ( ! ! this . definitions . command . aggregateId ) { aggregateId = dotty . get ( cmd , this . definitions . command . aggregateId ) ; } var streamInfo = { context : contextName , aggregate : aggregateName , aggregateId : aggregateId } ; if ( aggregate . isDestroyed ( ) ) { return new AggregateDestroyedError ( 'Aggregate has already been destroyed!' , { aggregateId : aggregate . id , aggregateRevision : aggregate . getRevision ( streamInfo ) } ) ; } return null ; }
Returns an error if the aggregate is destroyed.
@param {AggregateModel} aggregate The passed aggregate.
@param {Object}         cmd       The command.
@returns {AggregateDestroyedError}
Returns an error if the aggregate is destroyed .