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, }, }