Accomodate membership id (#6221)

* fix: accomodate membership id

* fix: remove only

* fix: event handling

* fix: tests

* fix: use transaction

* Remove useless test

---------

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Apoorv Mishra
2023-12-27 20:42:39 +05:30
committed by GitHub
parent 027357acad
commit 548a56e058
9 changed files with 106 additions and 28 deletions

View File

@@ -71,13 +71,18 @@ export default class CollectionGroupMembershipsStore extends Store<CollectionGro
id: collectionId,
groupId,
});
this.remove(`${groupId}-${collectionId}`);
const membership = Array.from(this.data.values()).find(
(m) => m.groupId === groupId && m.collectionId === collectionId
);
if (membership) {
this.remove(membership.id);
}
}
@action
removeCollectionMemberships = (collectionId: string) => {
this.data.forEach((membership, key) => {
if (key.includes(collectionId)) {
if (membership.collectionId === collectionId) {
this.remove(key);
}
});

View File

@@ -71,16 +71,31 @@ export default class MembershipsStore extends Store<Membership> {
id: collectionId,
userId,
});
this.remove(`${userId}-${collectionId}`);
this.rootStore.users.remove(userId);
this.revoke({ userId, collectionId });
}
@action
removeCollectionMemberships = (collectionId: string) => {
this.data.forEach((membership, key) => {
if (key.includes(collectionId)) {
if (membership.collectionId === collectionId) {
this.remove(key);
}
});
};
@action
revoke = ({
userId,
collectionId,
}: {
collectionId: string;
userId: string;
}) => {
const membership = Array.from(this.data.values()).find(
(m) => m.userId === userId && m.collectionId === collectionId
);
if (membership) {
this.remove(membership.id);
}
};
}