Add method to update user references

This commit is contained in:
Alberto Fernández Capel 2018-05-25 15:45:33 +01:00
parent 09ddc75126
commit 259d690f7c

View file

@ -43,6 +43,21 @@ module.exports = SubscriptionGroupHandler =
removeEmailInviteFromGroup: (adminUser_id, email, callback) ->
SubscriptionUpdater.removeEmailInviteFromGroup adminUser_id, email, callback
replaceUserReferencesInGroups: (oldId, newId, callback) ->
Subscription.update {admin_id: userStubId}, {admin_id: slUserId}, (error) ->
callback(error) if error?
# Mongo won't let us pull and addToSet in the same query, so do it in
# two. Note we need to add first, since the query is based on the old user.
query = {member_ids: userStubId}
addNewUserUpdate = $addToSet: {member_ids: slUserId}
removeOldUserUpdate = $pull: {member_ids: userStubId}
Subscription.update query, addNewUserUpdate, { multi: true }, (error) ->
return callback(error) if error?
Subscription.update query, removeOldUserUpdate, { multi: true }, callback
getPopulatedListOfMembers: (adminUser_id, callback)->
SubscriptionLocator.getUsersSubscription adminUser_id, (err, subscription)->
users = []