[FIX] users not correctly removed from groups

This commit is contained in:
2022-02-22 15:42:21 +00:00
parent 22ea9bcccf
commit bbc4fee64f

View File

@@ -926,7 +926,7 @@ async function updateUserGroupRole(snap, context) {
groupData.users = {}; groupData.users = {};
} }
if (typeof snap !== "undefined" && typeof snap.data() !== "undefined" && typeof snap.data().role !== "undefined") { if (typeof snap === "object" && snap !== null && snap.data !== undefined && typeof snap.data === "function" && typeof snap.data() === "object" && snap.data() !== null && snap.data().role !== undefined) {
groupData.users[context.params.userId] = snap.data().role; groupData.users[context.params.userId] = snap.data().role;
} else { } else {
delete groupData.users[context.params.userId]; delete groupData.users[context.params.userId];
@@ -963,6 +963,18 @@ exports.userGroupRoleUpdated = functions.firestore.document("users/{userId}/grou
return updateUserGroupRole(change.after, context); return updateUserGroupRole(change.after, context);
}); });
/**
* Removes an existing user from a group in the groups collection
* in Firestore, after the group has been removed from their
* document in the users collection.
* NOTE: Can't be unit tested.
* @return {boolean} Returns true on completion.
*/
exports.userGroupRoleDeleted = functions.firestore.document("users/{userId}/groups/{groupId}")
.onDelete(async (snap, context) => {
return updateUserGroupRole(null, context);
});
/** /**
* Generates a random, unused group join code. * Generates a random, unused group join code.
* @return {string} The join code. * @return {string} The join code.