-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set push notification settings
- Loading branch information
1 parent
7c1d2bd
commit 2c45ce1
Showing
21 changed files
with
267 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { checkedToPushNotificationSettings } from "@domain/notifications" | ||
|
||
import { AccountsRepository } from "@services/mongoose" | ||
|
||
export const updatePushNotificationSettings = async ({ | ||
accountId, | ||
notificationSettings, | ||
}: { | ||
accountId: AccountId | ||
notificationSettings: { | ||
enabled: boolean | ||
settings: { | ||
type: string | ||
enabled: boolean | ||
disabledSubtypes: string[] | ||
}[] | ||
} | ||
}): Promise<Account | ApplicationError> => { | ||
const checkedPushNotificationSettings = | ||
checkedToPushNotificationSettings(notificationSettings) | ||
|
||
if (checkedPushNotificationSettings instanceof Error) | ||
return checkedPushNotificationSettings | ||
|
||
const account = await AccountsRepository().findById(accountId) | ||
if (account instanceof Error) return account | ||
|
||
account.pushNotificationSettings = checkedPushNotificationSettings | ||
|
||
return AccountsRepository().update(account) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/graphql/public/types/object/push-notification-settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { GT } from "@graphql/index" | ||
import PushNotificationSubType from "@graphql/shared/types/scalar/push-notification-sub-type" | ||
import PushNotificationType from "@graphql/shared/types/scalar/push-notification-type" | ||
|
||
export const PushNotificationSettings = GT.Object< | ||
PushNotificationSettings, | ||
GraphQLPublicContextAuth | ||
>({ | ||
name: "PushNotificationSettings", | ||
fields: () => ({ | ||
enabled: { | ||
type: GT.NonNull(GT.Boolean), | ||
resolve: (source) => source.enabled, | ||
}, | ||
settings: { | ||
type: GT.NonNull(GT.List(PushNotificationSetting)), | ||
resolve: (source) => source.settings, | ||
}, | ||
}), | ||
}) | ||
|
||
export const PushNotificationSetting = GT.Object< | ||
PushNotificationSetting, | ||
GraphQLPublicContextAuth | ||
>({ | ||
name: "PushNotificationSetting", | ||
fields: () => ({ | ||
type: { | ||
type: GT.NonNull(PushNotificationType), | ||
|
||
resolve: (source) => source.type, | ||
}, | ||
enabled: { | ||
type: GT.NonNull(GT.Boolean), | ||
resolve: (source) => source.enabled, | ||
}, | ||
disabledSubtypes: { | ||
type: GT.NonNull(GT.List(PushNotificationSubType)), | ||
resolve: (source) => source.disabledSubtypes, | ||
}, | ||
}), | ||
}) |
Oops, something went wrong.