Skip to content

Commit

Permalink
chore: refactor interface
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Sep 18, 2023
1 parent 3a0d2d3 commit bba12c7
Show file tree
Hide file tree
Showing 52 changed files with 792 additions and 371 deletions.
76 changes: 55 additions & 21 deletions dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Account
id: ID!
level: AccountLevel!
limits: AccountLimits!
pushNotificationSettings: PushNotificationSettings!
notificationSettings: NotificationSettings!
realtimePrice: RealtimePrice!
transactions(
"""Returns the items in the list that come after the specified cursor."""
Expand All @@ -57,6 +57,32 @@ type AccountDeletePayload
success: Boolean!
}

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

input AccountDisableNotificationChannelInput
@join__type(graph: PUBLIC)
{
channel: NotificationChannel!
}

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

input AccountEnableNotificationChannelInput
@join__type(graph: PUBLIC)
{
channel: NotificationChannel!
}

enum AccountLevel
@join__type(graph: PUBLIC)
{
Expand Down Expand Up @@ -121,14 +147,7 @@ type AccountUpdateDisplayCurrencyPayload
errors: [Error!]!
}

input AccountUpdatePushNotificationSettingsInput
@join__type(graph: PUBLIC)
{
disabledPushNotificationTypes: [PushNotificationType]!
pushNotificationsEnabled: Boolean!
}

type AccountUpdatePushNotificationSettingsPayload
type AccountUpdateNotificationSettingsPayload
@join__type(graph: PUBLIC)
{
account: ConsumerAccount
Expand Down Expand Up @@ -282,7 +301,7 @@ type ConsumerAccount implements Account
id: ID!
level: AccountLevel!
limits: AccountLimits!
pushNotificationSettings: PushNotificationSettings!
notificationSettings: NotificationSettings!

"""List the quiz questions of the consumer account"""
quiz: [Quiz!]!
Expand Down Expand Up @@ -832,9 +851,12 @@ type Mutation
@join__type(graph: PUBLIC)
{
accountDelete: AccountDeletePayload!
accountDisableNotificationCategoryForChannel(input: AccountDisableNotificationCategoryForChannelInput!): AccountUpdateNotificationSettingsPayload!
accountDisableNotificationChannel(input: AccountDisableNotificationChannelInput!): AccountUpdateNotificationSettingsPayload!
accountEnableNotificationCategoryForChannel(input: AccountEnableNotificationCategoryForChannelInput!): AccountUpdateNotificationSettingsPayload!
accountEnableNotificationChannel(input: AccountEnableNotificationChannelInput!): AccountUpdateNotificationSettingsPayload!
accountUpdateDefaultWalletId(input: AccountUpdateDefaultWalletIdInput!): AccountUpdateDefaultWalletIdPayload!
accountUpdateDisplayCurrency(input: AccountUpdateDisplayCurrencyInput!): AccountUpdateDisplayCurrencyPayload!
accountUpdatePushNotificationSettings(input: AccountUpdatePushNotificationSettingsInput!): AccountUpdatePushNotificationSettingsPayload!
callbackEndpointAdd(input: CallbackEndpointAddInput!): CallbackEndpointAddPayload!
callbackEndpointDelete(input: CallbackEndpointDeleteInput!): SuccessPayload!
captchaCreateChallenge: CaptchaCreateChallengePayload!
Expand Down Expand Up @@ -966,6 +988,28 @@ enum Network
testnet @join__enumValue(graph: PUBLIC)
}

scalar NotificationCategory
@join__type(graph: PUBLIC)

enum NotificationChannel
@join__type(graph: PUBLIC)
{
PUSH @join__enumValue(graph: PUBLIC)
}

type NotificationChannelSettings
@join__type(graph: PUBLIC)
{
disabledCategories: [NotificationCategory!]!
enabled: Boolean!
}

type NotificationSettings
@join__type(graph: PUBLIC)
{
push: NotificationChannelSettings!
}

"""An address for an on-chain bitcoin destination"""
scalar OnChainAddress
@join__type(graph: PUBLIC)
Expand Down Expand Up @@ -1231,16 +1275,6 @@ type PublicWallet
walletCurrency: WalletCurrency!
}

type PushNotificationSettings
@join__type(graph: PUBLIC)
{
disabledPushNotificationTypes: [PushNotificationType]!
pushNotificationsEnabled: Boolean!
}

scalar PushNotificationType
@join__type(graph: PUBLIC)

type Query
@join__type(graph: PUBLIC)
{
Expand Down
31 changes: 31 additions & 0 deletions src/app/accounts/disable-notification-category-for-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
checkedToNotificationCategory,
disableNotificationCategoryForChannel as disableNotificationCategory,
} from "@domain/notifications"
import { AccountsRepository } from "@services/mongoose"

export const disableNotificationCategoryForChannel = async ({
accountId,
notificationChannel,
notificationCategory,
}: {
accountId: AccountId
notificationChannel: NotificationChannel
notificationCategory: string
}): Promise<Account | ApplicationError> => {
const checkedNotificationCategory = checkedToNotificationCategory(notificationCategory)
if (checkedNotificationCategory instanceof Error) return checkedNotificationCategory

const account = await AccountsRepository().findById(accountId)
if (account instanceof Error) return account

const newNotificationSettings = disableNotificationCategory({
notificationSettings: account.notificationSettings,
notificationChannel,
notificationCategory: checkedNotificationCategory,
})

account.notificationSettings = newNotificationSettings

return AccountsRepository().update(account)
}
23 changes: 23 additions & 0 deletions src/app/accounts/disable-notification-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { setNotificationChannelIsEnabled } from "@domain/notifications"
import { AccountsRepository } from "@services/mongoose"

export const disableNotificationChannel = async ({
accountId,
notificationChannel,
}: {
accountId: AccountId
notificationChannel: NotificationChannel
}): Promise<Account | ApplicationError> => {
const account = await AccountsRepository().findById(accountId)
if (account instanceof Error) return account

const newNotificationSettings = setNotificationChannelIsEnabled({
notificationSettings: account.notificationSettings,
notificationChannel,
enabled: false,
})

account.notificationSettings = newNotificationSettings

return AccountsRepository().update(account)
}
31 changes: 31 additions & 0 deletions src/app/accounts/enable-notification-category-for-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
checkedToNotificationCategory,
enableNotificationCategoryForChannel as enableNotificationChannel,
} from "@domain/notifications"
import { AccountsRepository } from "@services/mongoose"

export const enableNotificationCategoryForChannel = async ({
accountId,
notificationChannel,
notificationCategory,
}: {
accountId: AccountId
notificationChannel: NotificationChannel
notificationCategory: string
}): Promise<Account | ApplicationError> => {
const checkedNotificationCategory = checkedToNotificationCategory(notificationCategory)
if (checkedNotificationCategory instanceof Error) return checkedNotificationCategory

const account = await AccountsRepository().findById(accountId)
if (account instanceof Error) return account

const newNotificationSettings = enableNotificationChannel({
notificationSettings: account.notificationSettings,
notificationChannel,
notificationCategory: checkedNotificationCategory,
})

account.notificationSettings = newNotificationSettings

return AccountsRepository().update(account)
}
23 changes: 23 additions & 0 deletions src/app/accounts/enable-notification-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { setNotificationChannelIsEnabled } from "@domain/notifications"
import { AccountsRepository } from "@services/mongoose"

export const enableNotificationChannel = async ({
accountId,
notificationChannel,
}: {
accountId: AccountId
notificationChannel: NotificationChannel
}): Promise<Account | ApplicationError> => {
const account = await AccountsRepository().findById(accountId)
if (account instanceof Error) return account

const newNotificationSettings = setNotificationChannelIsEnabled({
notificationSettings: account.notificationSettings,
notificationChannel,
enabled: true,
})

account.notificationSettings = newNotificationSettings

return AccountsRepository().update(account)
}
5 changes: 4 additions & 1 deletion src/app/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export * from "./update-display-currency"
export * from "./username-available"
export * from "./delete-business-map-info"
export * from "./upgrade-device-account"
export * from "./update-push-notification-settings"
export * from "./disable-notification-category-for-channel"
export * from "./enable-notification-category-for-channel"
export * from "./enable-notification-channel"
export * from "./disable-notification-channel"

const accounts = AccountsRepository()

Expand Down
2 changes: 1 addition & 1 deletion src/app/accounts/send-default-wallet-balance-to-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const sendDefaultWalletBalanceToAccounts = async () => {
deviceTokens: user.deviceTokens,
displayBalanceAmount: displayAmount,
recipientLanguage: user.language,
pushNotificationSettings: account.pushNotificationSettings,
notificationSettings: account.notificationSettings,
})

if (result instanceof DeviceTokensNotRegisteredNotificationsServiceError) {
Expand Down
28 changes: 0 additions & 28 deletions src/app/accounts/update-push-notification-settings.ts

This file was deleted.

20 changes: 10 additions & 10 deletions src/app/admin/send-admin-push-notification.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { checkedToAccountUuid } from "@domain/accounts"
import {
GaloyPushNotifications,
checkedToPushNotificationType,
GaloyNotificationCategories,
checkedToNotificationCategory,
} from "@domain/notifications"
import { AccountsRepository } from "@services/mongoose/accounts"
import { UsersRepository } from "@services/mongoose/users"
Expand All @@ -12,19 +12,19 @@ export const sendAdminPushNotification = async ({
title,
body,
data,
pushNotificationType,
notificationCategory,
}: {
accountId: string
title: string
body: string
data?: { [key: string]: string }
pushNotificationType?: string
notificationCategory?: string
}): Promise<true | ApplicationError> => {
const checkedPushNotificationType = pushNotificationType
? checkedToPushNotificationType(pushNotificationType)
: GaloyPushNotifications.AdminPushNotification
const checkedNotificationCategory = notificationCategory
? checkedToNotificationCategory(notificationCategory)
: GaloyNotificationCategories.AdminPushNotification

if (checkedPushNotificationType instanceof Error) return checkedPushNotificationType
if (checkedNotificationCategory instanceof Error) return checkedNotificationCategory

const accountId = checkedToAccountUuid(accountIdRaw)
if (accountId instanceof Error) return accountId
Expand All @@ -43,8 +43,8 @@ export const sendAdminPushNotification = async ({
title,
body,
data,
pushNotificationType: checkedPushNotificationType,
pushNotificationSettings: account.pushNotificationSettings,
notificationCategory: checkedNotificationCategory,
notificationSettings: account.notificationSettings,
})

return success
Expand Down
2 changes: 1 addition & 1 deletion src/app/payments/send-intraledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ const executePaymentViaIntraledger = async <
recipientDeviceTokens: recipientUser.deviceTokens,
recipientLanguage: recipientUser.language,
paymentAmount: { amount, currency: recipientWallet.currency },
recipientPushNotificationSettings: recipientAccount.pushNotificationSettings,
recipientNotificationSettings: recipientAccount.notificationSettings,
displayPaymentAmount: recipientDisplayAmount,
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/payments/send-lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ const executePaymentViaIntraledger = async <
displayPaymentAmount: recipientDisplayAmount,
paymentHash,
recipientDeviceTokens: recipientUser.deviceTokens,
recipientPushNotificationSettings: recipientAccount.pushNotificationSettings,
recipientNotificationSettings: recipientAccount.notificationSettings,
recipientLanguage: recipientUser.language,
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/wallets/add-pending-on-chain-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const addPendingTransaction = async ({
displayPaymentAmount: settlementDisplayAmount,
txHash: txId,
recipientDeviceTokens: recipientUser.deviceTokens,
recipientPushNotificationSettings: account.pushNotificationSettings,
recipientNotificationSettings: account.notificationSettings,
recipientLanguage: recipientUser.language,
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/wallets/add-settled-on-chain-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const addSettledTransactionBeforeFinally = async ({
displayPaymentAmount: displayAmount,
txHash,
recipientDeviceTokens: user.deviceTokens,
recipientPushNotificationSettings: account.pushNotificationSettings,
recipientNotificationSettings: account.notificationSettings,
recipientLanguage: user.language,
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/wallets/send-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ const executePaymentViaIntraledger = async <
paymentAmount: { amount, currency: recipientWalletCurrency },
displayPaymentAmount: recipientDisplayAmount,
recipientDeviceTokens: recipientUser.deviceTokens,
recipientPushNotificationSettings: recipientAccount.pushNotificationSettings,
recipientNotificationSettings: recipientAccount.notificationSettings,
recipientLanguage: recipientUser.language,
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/wallets/settle-payout-txn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const settlePayout = async (
displayPaymentAmount,
txHash,
senderDeviceTokens: user.deviceTokens,
senderPushNotificationSettings: account.pushNotificationSettings,
senderNotificationSettings: account.notificationSettings,
senderLanguage: user.language,
})

Expand Down
2 changes: 1 addition & 1 deletion src/app/wallets/update-pending-invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ const updatePendingInvoiceBeforeFinally = async ({
displayPaymentAmount,
paymentHash,
recipientDeviceTokens: recipientUser.deviceTokens,
recipientPushNotificationSettings: recipientAccount.pushNotificationSettings,
recipientNotificationSettings: recipientAccount.notificationSettings,
recipientLanguage: recipientUser.language,
})

Expand Down
Loading

0 comments on commit bba12c7

Please sign in to comment.