Closed gstrit closed 8 years ago
business rules only applies on 1 aggregate (so you may need a personS aggregate)
I have to have a person and a persons aggregate ? I'm not sure to understand how it should work
no, just a persons aggregate
OK but can I apply a command createOnePerson to the persons aggregate ? Thank you for your answers
Yes, an aggregate is not an object. it's a container for intensions.
Ok I understand now how it should work but it doesn't work...
module.exports = require('cqrs-domain').definePreCondition({
name: 'createPlayer',
version: 0,
description: 'unique email address'
}, function (data, agg) {
var found = _.find(agg.get('players'), function (player) {
return player.firstname === data.firstname;
});
if (found) {
throw new Error('email already used');
}
});
agg.get('players') is always empty.
how does your defineEvent file for playerCreated looks like?
module.exports = require('cqrs-domain').defineEvent({
name: 'playerCreated'
},
function (data, aggregate) {
aggregate.get('players').push(data);
});
is that function called?
yes it is
do you have this project hosted on github? can i look at it?
You have to send all createPlayer commands with the same aggregateId
In my domain, a player is an aggregate root not the collection. If I understand how it works, when a client send a command to update a player, he has to fill the id of the collection as the aggregateId and not the id of the player, right ?
no...
to play a bit, just extend your commands with (cmd.payload.id = 'same aggregate Id for all commands';
)
the id of your collection player should be passed in the payload like (cmd.payload.playerId = vm.id;
)
Ok thanks
Hi, I don't understand how to create a business rule which says : email adress is unique for all persons. I'm not able to access to the persons repository. Thanks