thenativeweb / node-cqrs-domain

Node-cqrs-domain is a node.js module based on nodeEventStore that. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
http://cqrs.js.org/pages/domain.html
MIT License
269 stars 57 forks source link

Access meta in command #140

Closed bikerp closed 5 years ago

bikerp commented 5 years ago

Hi, is it possible to access meta in command? Thanks

nanov commented 5 years ago

Sure, you could do something like that ( ES6 syntax, assuming your payload is defined at payload and metadata at metadata) :

module.exports = require('cqrs-domain').defineCommand({
  name: 'enterNewPerson',
  version: 1,
  payload: '',
  // ... whatever else you might need
}, ({ payload, metadata }, aggregate) => {
  if (metadata.something)
      aggregate.apply('metadataDependantEvent', { my: 'eventPayload' });
  aggregate.apply('enteredNewPerson', payload);
});
bikerp commented 5 years ago

Thanks, the payload: '', did the trick.