* Fix major issue with SQLite transactions + aync code causing collisions

This commit is contained in:
Bryan Ashby 2017-09-16 17:13:11 -06:00
parent 68247d87e8
commit 1e250f06d9
8 changed files with 116 additions and 122 deletions

View file

@ -33,8 +33,13 @@ function getGroupsForUser(userId, cb) {
});
}
function addUserToGroup(userId, groupName, cb) {
userDb.run(
function addUserToGroup(userId, groupName, transOrDb, cb) {
if(!_.isFunction(cb) && _.isFunction(transOrDb)) {
cb = transOrDb;
transOrDb = userDb;
}
transOrDb.run(
'REPLACE INTO user_group_member (group_name, user_id) ' +
'VALUES(?, ?);',
[ groupName, userId ],
@ -44,10 +49,10 @@ function addUserToGroup(userId, groupName, cb) {
);
}
function addUserToGroups(userId, groups, cb) {
function addUserToGroups(userId, groups, transOrDb, cb) {
async.each(groups, function item(groupName, next) {
addUserToGroup(userId, groupName, next);
addUserToGroup(userId, groupName, transOrDb, next);
}, function complete(err) {
cb(err);
});