Updating other subscription part when deleting a subscription
This commit is contained in:
1 parent
12bbc525dc
commit
f7a8d6ad9a
1 file changed
+14
-1
@@ -91,6 +91,14 @@ const User: Component<Props> = (props) => {
|
||||
return { username, ...userDocument };
|
||||
};
|
||||
|
||||
const removeSubscription = (userDocument: any) => {
|
||||
const subscriptions = userDocument.subscriptions || [];
|
||||
userDocument.subscriptions = subscriptions.filter(
|
||||
(subscription: any) => subscription.username !== username
|
||||
);
|
||||
return { username, ...userDocument };
|
||||
};
|
||||
|
||||
const defaultUserDocument = {
|
||||
database,
|
||||
};
|
||||
@@ -98,7 +106,7 @@ const User: Component<Props> = (props) => {
|
||||
for (let i = 0; i < updatedSubscriptions.length; i++) {
|
||||
let subscription = updatedSubscriptions[i];
|
||||
if (!isIn(subscription.username, subscriptions)) {
|
||||
update(
|
||||
await update(
|
||||
userId(subscription.username, database),
|
||||
addSubscription,
|
||||
defaultUserDocument
|
||||
@@ -115,6 +123,11 @@ const User: Component<Props> = (props) => {
|
||||
for (let i = 0; i < subscriptions.length; i++) {
|
||||
let subscription = subscriptions[i];
|
||||
if (!isIn(subscription.username, updatedSubscriptions)) {
|
||||
await update(
|
||||
userId(subscription.username, database),
|
||||
removeSubscription,
|
||||
defaultUserDocument
|
||||
);
|
||||
console.log({
|
||||
caller: 'User / submitHandler / deleted subscription',
|
||||
username: subscription.username,
|
||||
|
||||
Reference in new issue
Block a user