Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business rule fail doesnt cause save to cancel #13

Closed
ssolbak opened this issue Nov 18, 2013 · 9 comments
Closed

Business rule fail doesnt cause save to cancel #13

ssolbak opened this issue Nov 18, 2013 · 9 comments

Comments

@ssolbak
Copy link

ssolbak commented Nov 18, 2013

This code looks great. I've spent the day digging into it but do have a couple issues:

I took an exact copy of the sample and changed itemBusinessRules as follows in the code below. All I did was add a rule that you cant add text that already exists.

Also according to other people, debugging with WebStorm seems to break the functionality. Has anyone else solved this? Its a real pain to not have debugging.

Thanks,
Sean

PS I added the code to init the repository in the domain server.js
PSS I took Udis course a couple years ago. Is the idea to have a separate node instance per AC or is it ok to have multiple aggregates in the same application. I only really have one component that I need to scale like crazy and am ok having the rest on the same node.

var repository = require('viewmodel').read
, itemRepo = repository.extend({collectionName: 'item'});

module.exports = {
itemAggregate: [

function checkForError(changed, previous, events, callback) {

  itemRepo.find({text: changed.text}, function(err, items) {
    if (err){
      //todo
    }

    console.log("There are " + items.length + " items with text= " + changed.text);

    if(items.length > 0){
      return callback('cannot use existing text');
    }
  });

  if (changed.text.toLowerCase().indexOf('error') >= 0) {
    return callback('This is just a sample rule!');
  }

  callback(null);
}

]
};

@adrai
Copy link
Contributor

adrai commented Nov 18, 2013

Can you try with forkEventDispatching = false ?

@ssolbak
Copy link
Author

ssolbak commented Nov 19, 2013

forkEventDispatching = false fixes the debugging issues thanks!

I did nothing but edit server.js to mongoDb on the host and the server.js modifications are below. I have the latest of all the npm modules. I am developing on a windows box using WebStorm.

var repository = require('viewmodel').read;

var options = {
commandHandlersPath: __dirname + '/commandHandlers',
aggregatesPath: __dirname + '/aggregates',
sagaHandlersPath: __dirname + '/sagaHandlers',
sagasPath: __dirname + '/sagas',
forkEventDispatching: false,
eventStore: {
type: 'mongoDb', //'mongoDb',
dbName: 'tmptest'
},
commandQueue: {
type: 'mongoDb', //'mongoDb',
dbName: 'tmptest'
},
repository: {
type: 'mongoDb', //'mongoDb',
dbName: 'tmptest'
}
};

repository.init(options.repository, function(err) {
console.log("initializing repository done");
});

@ssolbak
Copy link
Author

ssolbak commented Nov 20, 2013

Just to clarify (it was a bit confusing) the forkEventDispatching = false fixed the debugging issue but the business rule issue is still outstanding. Even though the business rule doesnt pass, the save still occurs.

S

@adrai
Copy link
Contributor

adrai commented Nov 20, 2013

In the next few days I hope to look at it... sorry... I'm under pressure at the moment... :-(

@ssolbak
Copy link
Author

ssolbak commented Nov 20, 2013

No worries :) Just re-read my post and I was a little unclear. I'll take a look this weekend as well.

@adrai
Copy link
Contributor

adrai commented Nov 21, 2013

ok try with latest release v0.5.3

@ssolbak
Copy link
Author

ssolbak commented Nov 23, 2013

I get the following error... "Error: Callback was already called."

@adrai
Copy link
Contributor

adrai commented Nov 23, 2013

Please check if you call the callback twice in the business rule... If it's like the above code snipped it will call it twice...

@ssolbak
Copy link
Author

ssolbak commented Nov 24, 2013

Oops ya sorry my bad. The fix is good!

@adrai adrai closed this as completed Nov 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants