Skip to content

Commit

Permalink
chore: address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Sep 19, 2023
1 parent 54d097e commit deb5cb9
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 80 deletions.
12 changes: 6 additions & 6 deletions dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ type AccountDeletePayload
success: Boolean!
}

input AccountDisableNotificationCategoryForChannelInput
input AccountDisableNotificationCategoryInput
@join__type(graph: PUBLIC)
{
category: NotificationCategory!
channel: NotificationChannel!
channel: NotificationChannel
}

input AccountDisableNotificationChannelInput
Expand All @@ -70,11 +70,11 @@ input AccountDisableNotificationChannelInput
channel: NotificationChannel!
}

input AccountEnableNotificationCategoryForChannelInput
input AccountEnableNotificationCategoryInput
@join__type(graph: PUBLIC)
{
category: NotificationCategory!
channel: NotificationChannel!
channel: NotificationChannel
}

input AccountEnableNotificationChannelInput
Expand Down Expand Up @@ -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!
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Account | ApplicationError> => {
const checkedNotificationCategory = checkedToNotificationCategory(notificationCategory)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Account | ApplicationError> => {
const checkedNotificationCategory = checkedToNotificationCategory(notificationCategory)
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/app/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
76 changes: 48 additions & 28 deletions src/domain/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
10 changes: 4 additions & 6 deletions src/graphql/public/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ 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),
},
}),
})

const AccountDisableNotificationCategoryForChannelMutation = GT.Field<
const AccountDisableNotificationCategoryMutation = GT.Field<
null,
GraphQLPublicContextAuth,
{
input: {
channel: NotificationChannel | Error
channel?: NotificationChannel | Error
category: NotificationCategory
}
}
Expand All @@ -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,
Expand All @@ -57,4 +57,4 @@ const AccountDisableNotificationCategoryForChannelMutation = GT.Field<
},
})

export default AccountDisableNotificationCategoryForChannelMutation
export default AccountDisableNotificationCategoryMutation
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ 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),
},
}),
})

const AccountEnableNotificationCategoryForChannelMutation = GT.Field<
const AccountEnableNotificationCategoryMutation = GT.Field<
null,
GraphQLPublicContextAuth,
{
input: {
channel: NotificationChannel | Error
channel?: NotificationChannel | Error
category: NotificationCategory
}
}
Expand All @@ -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,
Expand All @@ -57,4 +57,4 @@ const AccountEnableNotificationCategoryForChannelMutation = GT.Field<
},
})

export default AccountEnableNotificationCategoryForChannelMutation
export default AccountEnableNotificationCategoryMutation
12 changes: 6 additions & 6 deletions src/graphql/public/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!
Expand Down
Loading

0 comments on commit deb5cb9

Please sign in to comment.