From 6ac467764d12526cff1ee06540ea627e7ffb39cd Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 4 Oct 2022 08:38:20 -0600 Subject: [PATCH] Fix unsubscribe all update --- functions/src/unsubscribe.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/functions/src/unsubscribe.ts b/functions/src/unsubscribe.ts index 57a6d183..0429fcd6 100644 --- a/functions/src/unsubscribe.ts +++ b/functions/src/unsubscribe.ts @@ -34,17 +34,20 @@ export const unsubscribe: EndpointDefinition = { const previousDestinations = user.notificationPreferences[notificationSubscriptionType] + let newDestinations = previousDestinations + if (wantsToOptOutAll) newDestinations.push('email') + else + newDestinations = previousDestinations.filter( + (destination) => destination !== 'email' + ) + console.log(previousDestinations) const { email } = user const update: Partial = { notificationPreferences: { ...user.notificationPreferences, - [notificationSubscriptionType]: wantsToOptOutAll - ? previousDestinations.push('email') - : previousDestinations.filter( - (destination) => destination !== 'email' - ), + [notificationSubscriptionType]: newDestinations, }, }