( email: string, emailType: 'all' | 'marketing' | 'updates' | 'notifications' = 'all' )
| 150 | * Check if user has unsubscribed from a specific email type |
| 151 | */ |
| 152 | export async function isUnsubscribed( |
| 153 | email: string, |
| 154 | emailType: 'all' | 'marketing' | 'updates' | 'notifications' = 'all' |
| 155 | ): Promise<boolean> { |
| 156 | try { |
| 157 | const preferences = await getEmailPreferences(email) |
| 158 | if (!preferences) return false |
| 159 | |
| 160 | if (preferences.unsubscribeAll) return true |
| 161 | |
| 162 | switch (emailType) { |
| 163 | case 'marketing': |
| 164 | return preferences.unsubscribeMarketing || false |
| 165 | case 'updates': |
| 166 | return preferences.unsubscribeUpdates || false |
| 167 | case 'notifications': |
| 168 | return preferences.unsubscribeNotifications || false |
| 169 | default: |
| 170 | return false |
| 171 | } |
| 172 | } catch (error) { |
| 173 | logger.error('Error checking unsubscribe status:', error) |
| 174 | return false |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Unsubscribe user from all emails |
no test coverage detected