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