Fix new user pre-creation event

* We're abusing Events a bit here, so have to manually track callbacks
This commit is contained in:
Bryan Ashby 2023-02-20 19:14:46 -07:00
parent e35fc5bf41
commit 2495430fae
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
1 changed files with 16 additions and 4 deletions

View File

@ -525,12 +525,24 @@ module.exports = class User {
return callback(null, trans); return callback(null, trans);
}, },
function newUserPreEvent(trans, callback) { function newUserPreEvent(trans, callback) {
Events.emit(Events.getSystemEvents().NewUserPrePersist, { const eventName = Events.getSystemEvents().NewUserPrePersist;
const subCount = Events.listenerCount(eventName);
if (subCount < 1) {
return callback(null, trans);
}
let returned = 0;
const cbWrapper = e => {
++returned;
if (returned >= subCount) {
return callback(e, trans);
}
};
Events.emit(eventName, {
user: self, user: self,
sessionId: createUserInfo.sessionId, sessionId: createUserInfo.sessionId,
callback: err => { callback: cbWrapper,
return callback(err, trans);
},
}); });
}, },
function saveAll(trans, callback) { function saveAll(trans, callback) {