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

PreLoad conditions are not called #82

Closed AlexandreRoba closed 8 years ago

AlexandreRoba commented 8 years ago

Hello,

I have a domain with one aggregate and two commands. I have defined two preload conditions for each commands. I can see on the getInfo for each commands both preload conditions. image When I submit the command matching the preload condition commands, none of the preload function are called. I have added logging and breakpoints. None of them are called or stopped at. the preload condition are qui simple. I'm for exemple checking for a meta with a userId:

module.exports = require('cqrs-domain').definePreLoadCondition({
    name: 'createNoise',
    description:'Create noise require authentication'
}, function (data) {
    let meta = data.meta || {};
    let userId = meta.userId || null;
    if(!userId){
        return new Error('Authentication is required');
    }
});

Any idea?

thanks for your help,

Alex

AlexandreRoba commented 8 years ago

Hello,

After a little more investigation I find out that setting the priority did resolve the issue. Isn't this suppose to be optional? Nevertheless it now works with the priority set.

thanks,

Alex.

adrai commented 8 years ago

Yes the priority is optional (defaults to Infinity), it should work without priority too.

repkins commented 7 years ago

Hello, @adrai!

I just also encountered with this issue by its nature, and, as there OP pointed cause of this by setting priority, for me does not solve this solution.

I have made own investigation by debugging to figure out how it actually handles pre-load conditions of command. and I have cause of this. The problem is place where it checks for defined pre-load conditions by checking it's length of pre-load conditions array in particular command instance. Acually it looks in preConditions array instead of preLoadConditions which means it apply pre-load conditions only if pre conditions is present in command. screenshot_2017-01-20_11-32-25

adrai commented 7 years ago

You're right... will fix asap

adrai commented 7 years ago

v2.4.8