diff --git a/dev/apollo-federation/supergraph.graphql b/dev/apollo-federation/supergraph.graphql index 24459835a0..ed23e006ea 100644 --- a/dev/apollo-federation/supergraph.graphql +++ b/dev/apollo-federation/supergraph.graphql @@ -57,11 +57,11 @@ type AccountDeletePayload success: Boolean! } -input AccountDisableNotificationCategoryForChannelInput +input AccountDisableNotificationCategoryInput @join__type(graph: PUBLIC) { category: NotificationCategory! - channel: NotificationChannel! + channel: NotificationChannel } input AccountDisableNotificationChannelInput @@ -70,11 +70,11 @@ input AccountDisableNotificationChannelInput channel: NotificationChannel! } -input AccountEnableNotificationCategoryForChannelInput +input AccountEnableNotificationCategoryInput @join__type(graph: PUBLIC) { category: NotificationCategory! - channel: NotificationChannel! + channel: NotificationChannel } input AccountEnableNotificationChannelInput @@ -851,9 +851,9 @@ type Mutation @join__type(graph: PUBLIC) { accountDelete: AccountDeletePayload! - accountDisableNotificationCategoryForChannel(input: AccountDisableNotificationCategoryForChannelInput!): AccountUpdateNotificationSettingsPayload! + accountDisableNotificationCategory(input: AccountDisableNotificationCategoryInput!): AccountUpdateNotificationSettingsPayload! accountDisableNotificationChannel(input: AccountDisableNotificationChannelInput!): AccountUpdateNotificationSettingsPayload! - accountEnableNotificationCategoryForChannel(input: AccountEnableNotificationCategoryForChannelInput!): AccountUpdateNotificationSettingsPayload! + accountEnableNotificationCategory(input: AccountEnableNotificationCategoryInput!): AccountUpdateNotificationSettingsPayload! accountEnableNotificationChannel(input: AccountEnableNotificationChannelInput!): AccountUpdateNotificationSettingsPayload! accountUpdateDefaultWalletId(input: AccountUpdateDefaultWalletIdInput!): AccountUpdateDefaultWalletIdPayload! accountUpdateDisplayCurrency(input: AccountUpdateDisplayCurrencyInput!): AccountUpdateDisplayCurrencyPayload! diff --git a/src/app/accounts/enable-notification-category-for-channel.ts b/src/app/accounts/disable-notification-category.ts similarity index 77% rename from src/app/accounts/enable-notification-category-for-channel.ts rename to src/app/accounts/disable-notification-category.ts index 90aac3a1e9..8bc1bc4014 100644 --- a/src/app/accounts/enable-notification-category-for-channel.ts +++ b/src/app/accounts/disable-notification-category.ts @@ -1,16 +1,16 @@ import { checkedToNotificationCategory, - enableNotificationCategoryForChannel as enableNotificationChannel, + disableNotificationCategory as domainDisableNotificationCategory, } from "@domain/notifications" import { AccountsRepository } from "@services/mongoose" -export const enableNotificationCategoryForChannel = async ({ +export const disableNotificationCategory = async ({ accountId, notificationChannel, notificationCategory, }: { accountId: AccountId - notificationChannel: NotificationChannel + notificationChannel?: NotificationChannel notificationCategory: string }): Promise => { const checkedNotificationCategory = checkedToNotificationCategory(notificationCategory) @@ -19,7 +19,7 @@ export const enableNotificationCategoryForChannel = async ({ const account = await AccountsRepository().findById(accountId) if (account instanceof Error) return account - const newNotificationSettings = enableNotificationChannel({ + const newNotificationSettings = domainDisableNotificationCategory({ notificationSettings: account.notificationSettings, notificationChannel, notificationCategory: checkedNotificationCategory, diff --git a/src/app/accounts/disable-notification-category-for-channel.ts b/src/app/accounts/enable-notification-category.ts similarity index 77% rename from src/app/accounts/disable-notification-category-for-channel.ts rename to src/app/accounts/enable-notification-category.ts index ddbd2a3386..6248e6a499 100644 --- a/src/app/accounts/disable-notification-category-for-channel.ts +++ b/src/app/accounts/enable-notification-category.ts @@ -1,16 +1,16 @@ import { checkedToNotificationCategory, - disableNotificationCategoryForChannel as disableNotificationCategory, + enableNotificationCategory as domainEnableNotificationCategory, } from "@domain/notifications" import { AccountsRepository } from "@services/mongoose" -export const disableNotificationCategoryForChannel = async ({ +export const enableNotificationCategory = async ({ accountId, notificationChannel, notificationCategory, }: { accountId: AccountId - notificationChannel: NotificationChannel + notificationChannel?: NotificationChannel notificationCategory: string }): Promise => { const checkedNotificationCategory = checkedToNotificationCategory(notificationCategory) @@ -19,7 +19,7 @@ export const disableNotificationCategoryForChannel = async ({ const account = await AccountsRepository().findById(accountId) if (account instanceof Error) return account - const newNotificationSettings = disableNotificationCategory({ + const newNotificationSettings = domainEnableNotificationCategory({ notificationSettings: account.notificationSettings, notificationChannel, notificationCategory: checkedNotificationCategory, diff --git a/src/app/accounts/index.ts b/src/app/accounts/index.ts index acbf3d7f18..1daba7632d 100644 --- a/src/app/accounts/index.ts +++ b/src/app/accounts/index.ts @@ -21,8 +21,8 @@ export * from "./update-display-currency" export * from "./username-available" export * from "./delete-business-map-info" export * from "./upgrade-device-account" -export * from "./disable-notification-category-for-channel" -export * from "./enable-notification-category-for-channel" +export * from "./disable-notification-category" +export * from "./enable-notification-category" export * from "./enable-notification-channel" export * from "./disable-notification-channel" diff --git a/src/domain/notifications/index.ts b/src/domain/notifications/index.ts index 1e165c4612..71bdf88a42 100644 --- a/src/domain/notifications/index.ts +++ b/src/domain/notifications/index.ts @@ -57,54 +57,74 @@ export const setNotificationChannelIsEnabled = ({ } } -export const enableNotificationCategoryForChannel = ({ +export const enableNotificationCategory = ({ notificationSettings, notificationChannel, notificationCategory, }: { notificationSettings: NotificationSettings - notificationChannel: NotificationChannel + notificationChannel?: NotificationChannel notificationCategory: NotificationCategory }): NotificationSettings => { - const notificationChannelSettings = notificationSettings[notificationChannel] - const disabledCategories = notificationChannelSettings.disabledCategories - - const newNotificationSettings = { - enabled: notificationChannelSettings.enabled, - disabledCategories: disabledCategories.filter( - (category) => category !== notificationCategory, - ), + const notificationChannelsToUpdate: NotificationChannel[] = notificationChannel + ? [notificationChannel] + : Object.values(NotificationChannel) + + let newNotificationSettings = notificationSettings + + for (const notificationChannel of notificationChannelsToUpdate) { + const notificationChannelSettings = notificationSettings[notificationChannel] + const disabledCategories = notificationChannelSettings.disabledCategories + + const newNotificationChannelSettings = { + enabled: notificationChannelSettings.enabled, + disabledCategories: disabledCategories.filter( + (category) => category !== notificationCategory, + ), + } + + newNotificationSettings = { + ...notificationSettings, + [notificationChannel]: newNotificationChannelSettings, + } } - return { - ...notificationSettings, - [notificationChannel]: newNotificationSettings, - } + return newNotificationSettings } -export const disableNotificationCategoryForChannel = ({ +export const disableNotificationCategory = ({ notificationSettings, notificationChannel, notificationCategory, }: { notificationSettings: NotificationSettings - notificationChannel: NotificationChannel + notificationChannel?: NotificationChannel notificationCategory: NotificationCategory }): NotificationSettings => { - const notificationChannelSettings = notificationSettings[notificationChannel] - const disabledCategories = notificationChannelSettings.disabledCategories - disabledCategories.push(notificationCategory) - const uniqueDisabledCategories = [...new Set(disabledCategories)] - - const newNotificationSettings = { - enabled: notificationChannelSettings.enabled, - disabledCategories: uniqueDisabledCategories, + const notificationChannelsToUpdate: NotificationChannel[] = notificationChannel + ? [notificationChannel] + : Object.values(NotificationChannel) + + let newNotificationSettings = notificationSettings + + for (const notificationChannel of notificationChannelsToUpdate) { + const notificationChannelSettings = notificationSettings[notificationChannel] + const disabledCategories = notificationChannelSettings.disabledCategories + disabledCategories.push(notificationCategory) + const uniqueDisabledCategories = [...new Set(disabledCategories)] + + const newNotificationChannelSettings = { + enabled: notificationChannelSettings.enabled, + disabledCategories: uniqueDisabledCategories, + } + + newNotificationSettings = { + ...notificationSettings, + [notificationChannel]: newNotificationChannelSettings, + } } - return { - ...notificationSettings, - [notificationChannel]: newNotificationSettings, - } + return newNotificationSettings } export const shouldSendNotification = ({ diff --git a/src/graphql/public/mutations.ts b/src/graphql/public/mutations.ts index 35722fe505..892aabc502 100644 --- a/src/graphql/public/mutations.ts +++ b/src/graphql/public/mutations.ts @@ -49,8 +49,8 @@ import UserTotpDeleteMutation from "@graphql/public/root/mutation/user-totp-dele import CallbackEndpointAdd from "./root/mutation/callback-endpoint-add" import CallbackEndpointDelete from "./root/mutation/callback-endpoint-delete" -import AccountEnableNotificationCategoryForChannelMutation from "./root/mutation/account-enable-notification-category-for-channel" -import AccountDisableNotificationCategoryForChannelMutation from "./root/mutation/account-disable-notification-category-for-channel" +import AccountEnableNotificationCategoryMutation from "./root/mutation/account-enable-notification-category-for-channel" +import AccountDisableNotificationCategoryMutation from "./root/mutation/account-disable-notification-category-for-channel" import AccountEnableNotificationChannelMutation from "./root/mutation/account-enable-notification-channel" import AccountDisableNotificationChannelMutation from "./root/mutation/account-disable-notification-channel" @@ -90,10 +90,8 @@ export const mutationFields = { userContactUpdateAlias: UserContactUpdateAliasMutation, accountUpdateDefaultWalletId: AccountUpdateDefaultWalletIdMutation, accountUpdateDisplayCurrency: AccountUpdateDisplayCurrencyMutation, - accountEnableNotificationCategoryForChannel: - AccountEnableNotificationCategoryForChannelMutation, - accountDisableNotificationCategoryForChannel: - AccountDisableNotificationCategoryForChannelMutation, + accountEnableNotificationCategory: AccountEnableNotificationCategoryMutation, + accountDisableNotificationCategory: AccountDisableNotificationCategoryMutation, accountEnableNotificationChannel: AccountEnableNotificationChannelMutation, accountDisableNotificationChannel: AccountDisableNotificationChannelMutation, diff --git a/src/graphql/public/root/mutation/account-disable-notification-category-for-channel.ts b/src/graphql/public/root/mutation/account-disable-notification-category-for-channel.ts index 4c0d82e3fa..0a551e35bd 100644 --- a/src/graphql/public/root/mutation/account-disable-notification-category-for-channel.ts +++ b/src/graphql/public/root/mutation/account-disable-notification-category-for-channel.ts @@ -6,11 +6,11 @@ import { mapAndParseErrorForGqlResponse } from "@graphql/error-map" import NotificationChannel from "@graphql/shared/types/scalar/notification-channel" import NotificationCategory from "@graphql/shared/types/scalar/notification-category" -const AccountDisableNotificationCategoryForChannelInput = GT.Input({ - name: "AccountDisableNotificationCategoryForChannelInput", +const AccountDisableNotificationCategoryInput = GT.Input({ + name: "AccountDisableNotificationCategoryInput", fields: () => ({ channel: { - type: GT.NonNull(NotificationChannel), + type: NotificationChannel, }, category: { type: GT.NonNull(NotificationCategory), @@ -18,12 +18,12 @@ const AccountDisableNotificationCategoryForChannelInput = GT.Input({ }), }) -const AccountDisableNotificationCategoryForChannelMutation = GT.Field< +const AccountDisableNotificationCategoryMutation = GT.Field< null, GraphQLPublicContextAuth, { input: { - channel: NotificationChannel | Error + channel?: NotificationChannel | Error category: NotificationCategory } } @@ -33,14 +33,14 @@ const AccountDisableNotificationCategoryForChannelMutation = GT.Field< }, type: GT.NonNull(AccountUpdateNotificationSettingsPayload), args: { - input: { type: GT.NonNull(AccountDisableNotificationCategoryForChannelInput) }, + input: { type: GT.NonNull(AccountDisableNotificationCategoryInput) }, }, resolve: async (_, args, { domainAccount }: { domainAccount: Account }) => { const { channel, category } = args.input if (channel instanceof Error) return { errors: [{ message: channel.message }] } - const result = await Accounts.disableNotificationCategoryForChannel({ + const result = await Accounts.disableNotificationCategory({ accountId: domainAccount.id, notificationChannel: channel, notificationCategory: category, @@ -57,4 +57,4 @@ const AccountDisableNotificationCategoryForChannelMutation = GT.Field< }, }) -export default AccountDisableNotificationCategoryForChannelMutation +export default AccountDisableNotificationCategoryMutation diff --git a/src/graphql/public/root/mutation/account-enable-notification-category-for-channel.ts b/src/graphql/public/root/mutation/account-enable-notification-category-for-channel.ts index 89c72b799a..f0b309e3a4 100644 --- a/src/graphql/public/root/mutation/account-enable-notification-category-for-channel.ts +++ b/src/graphql/public/root/mutation/account-enable-notification-category-for-channel.ts @@ -6,11 +6,11 @@ import { mapAndParseErrorForGqlResponse } from "@graphql/error-map" import NotificationChannel from "@graphql/shared/types/scalar/notification-channel" import NotificationCategory from "@graphql/shared/types/scalar/notification-category" -const AccountEnableNotificationCategoryForChannelInput = GT.Input({ - name: "AccountEnableNotificationCategoryForChannelInput", +const AccountEnableNotificationCategoryInput = GT.Input({ + name: "AccountEnableNotificationCategoryInput", fields: () => ({ channel: { - type: GT.NonNull(NotificationChannel), + type: NotificationChannel, }, category: { type: GT.NonNull(NotificationCategory), @@ -18,12 +18,12 @@ const AccountEnableNotificationCategoryForChannelInput = GT.Input({ }), }) -const AccountEnableNotificationCategoryForChannelMutation = GT.Field< +const AccountEnableNotificationCategoryMutation = GT.Field< null, GraphQLPublicContextAuth, { input: { - channel: NotificationChannel | Error + channel?: NotificationChannel | Error category: NotificationCategory } } @@ -33,14 +33,14 @@ const AccountEnableNotificationCategoryForChannelMutation = GT.Field< }, type: GT.NonNull(AccountUpdateNotificationSettingsPayload), args: { - input: { type: GT.NonNull(AccountEnableNotificationCategoryForChannelInput) }, + input: { type: GT.NonNull(AccountEnableNotificationCategoryInput) }, }, resolve: async (_, args, { domainAccount }: { domainAccount: Account }) => { const { channel, category } = args.input if (channel instanceof Error) return { errors: [{ message: channel.message }] } - const result = await Accounts.enableNotificationCategoryForChannel({ + const result = await Accounts.enableNotificationCategory({ accountId: domainAccount.id, notificationChannel: channel, notificationCategory: category, @@ -57,4 +57,4 @@ const AccountEnableNotificationCategoryForChannelMutation = GT.Field< }, }) -export default AccountEnableNotificationCategoryForChannelMutation +export default AccountEnableNotificationCategoryMutation diff --git a/src/graphql/public/schema.graphql b/src/graphql/public/schema.graphql index 17d9d3b8ab..681fca2e67 100644 --- a/src/graphql/public/schema.graphql +++ b/src/graphql/public/schema.graphql @@ -30,18 +30,18 @@ type AccountDeletePayload { success: Boolean! } -input AccountDisableNotificationCategoryForChannelInput { +input AccountDisableNotificationCategoryInput { category: NotificationCategory! - channel: NotificationChannel! + channel: NotificationChannel } input AccountDisableNotificationChannelInput { channel: NotificationChannel! } -input AccountEnableNotificationCategoryForChannelInput { +input AccountEnableNotificationCategoryInput { category: NotificationCategory! - channel: NotificationChannel! + channel: NotificationChannel } input AccountEnableNotificationChannelInput { @@ -645,9 +645,9 @@ type MobileVersions { type Mutation { accountDelete: AccountDeletePayload! - accountDisableNotificationCategoryForChannel(input: AccountDisableNotificationCategoryForChannelInput!): AccountUpdateNotificationSettingsPayload! + accountDisableNotificationCategory(input: AccountDisableNotificationCategoryInput!): AccountUpdateNotificationSettingsPayload! accountDisableNotificationChannel(input: AccountDisableNotificationChannelInput!): AccountUpdateNotificationSettingsPayload! - accountEnableNotificationCategoryForChannel(input: AccountEnableNotificationCategoryForChannelInput!): AccountUpdateNotificationSettingsPayload! + accountEnableNotificationCategory(input: AccountEnableNotificationCategoryInput!): AccountUpdateNotificationSettingsPayload! accountEnableNotificationChannel(input: AccountEnableNotificationChannelInput!): AccountUpdateNotificationSettingsPayload! accountUpdateDefaultWalletId(input: AccountUpdateDefaultWalletIdInput!): AccountUpdateDefaultWalletIdPayload! accountUpdateDisplayCurrency(input: AccountUpdateDisplayCurrencyInput!): AccountUpdateDisplayCurrencyPayload! diff --git a/test/legacy-integration/notifications/notification.spec.ts b/test/legacy-integration/notifications/notification.spec.ts index 58164c39a3..d5df3ccaea 100644 --- a/test/legacy-integration/notifications/notification.spec.ts +++ b/test/legacy-integration/notifications/notification.spec.ts @@ -230,7 +230,7 @@ describe("notification", () => { expect(sendFilteredNotification.mock.calls.length).toBe(1) expect(sendFilteredNotification.mock.calls[0][0].title).toBe(title) expect(sendFilteredNotification.mock.calls[0][0].body).toBe(body) - expect(sendFilteredNotification.mock.calls[0][0].pushNotificationType).toBe( + expect(sendFilteredNotification.mock.calls[0][0].notificationCategory).toBe( GaloyNotificationCategories.Payments, ) }), @@ -277,7 +277,7 @@ describe("notification", () => { expect(sendFilteredNotification.mock.calls.length).toBe(1) expect(sendFilteredNotification.mock.calls[0][0].title).toBe(title) expect(sendFilteredNotification.mock.calls[0][0].body).toBe(body) - expect(sendFilteredNotification.mock.calls[0][0].pushNotificationType).toBe( + expect(sendFilteredNotification.mock.calls[0][0].notificationCategory).toBe( GaloyNotificationCategories.Payments, ) }), @@ -325,7 +325,7 @@ describe("notification", () => { expect(sendFilteredNotification.mock.calls.length).toBe(1) expect(sendFilteredNotification.mock.calls[0][0].title).toBe(title) expect(sendFilteredNotification.mock.calls[0][0].body).toBe(body) - expect(sendFilteredNotification.mock.calls[0][0].pushNotificationType).toBe( + expect(sendFilteredNotification.mock.calls[0][0].notificationCategory).toBe( GaloyNotificationCategories.Payments, ) }), @@ -372,7 +372,7 @@ describe("notification", () => { expect(sendFilteredNotification.mock.calls.length).toBe(1) expect(sendFilteredNotification.mock.calls[0][0].title).toBe(title) expect(sendFilteredNotification.mock.calls[0][0].body).toBe(body) - expect(sendFilteredNotification.mock.calls[0][0].pushNotificationType).toBe( + expect(sendFilteredNotification.mock.calls[0][0].notificationCategory).toBe( GaloyNotificationCategories.Payments, ) }), @@ -419,7 +419,7 @@ describe("notification", () => { expect(sendFilteredNotification.mock.calls.length).toBe(1) expect(sendFilteredNotification.mock.calls[0][0].title).toBe(title) expect(sendFilteredNotification.mock.calls[0][0].body).toBe(body) - expect(sendFilteredNotification.mock.calls[0][0].pushNotificationType).toBe( + expect(sendFilteredNotification.mock.calls[0][0].notificationCategory).toBe( GaloyNotificationCategories.Payments, ) }), diff --git a/test/unit/domain/notifications/index.spec.ts b/test/unit/domain/notifications/index.spec.ts index a3b8087f5f..00e5db7b5f 100644 --- a/test/unit/domain/notifications/index.spec.ts +++ b/test/unit/domain/notifications/index.spec.ts @@ -1,6 +1,6 @@ import { NotificationChannel, - disableNotificationCategoryForChannel, + disableNotificationCategory, setNotificationChannelIsEnabled, shouldSendNotification, } from "@domain/notifications" @@ -106,7 +106,7 @@ describe("Notifications - push notification filtering", () => { const notificationCategory = "transaction" as NotificationCategory - const result = disableNotificationCategoryForChannel({ + const result = disableNotificationCategory({ notificationSettings, notificationChannel, notificationCategory, @@ -133,7 +133,7 @@ describe("Notifications - push notification filtering", () => { const notificationChannel = NotificationChannel.Push - const result = disableNotificationCategoryForChannel({ + const result = disableNotificationCategory({ notificationSettings, notificationChannel, notificationCategory,