-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
Hi, I have the similar question: how to make checks for uniqueness in domain?
I tried to check it using eventDenormalizer by saving unique values (emails) into VM by listen domain events and then check it in preCondition:
import * as domain from "cqrs-domain";
export = domain.definePreCondition({
// @ts-ignore
name: ['createUser', 'updateUser'],
priority: 1,
payload: 'payload',
}, (data, aggregate, callback) => {
const usersRepo = require('../viewBuilders/user/usersCollection');
usersRepo.findViewModels({email: data.email}, (err, items) => {
if(items.length){
callback("Provided email is already exist in our database!");
} else {
callback(null);
}
});
});
but this way is not atomic, theoretically there can be situation when 2 users can create their accounts with the same emails. How to avoid this?
Metadata
Metadata
Assignees
Labels
No labels