@@ -76,13 +76,34 @@ export const findNotificationSettingByNotificationTypeAndUserAddress =
76
76
}
77
77
} ;
78
78
79
+ export const findNotificationSettingById = async (
80
+ id : number ,
81
+ ) : Promise < NotificationSetting | null > => {
82
+ try {
83
+ return await NotificationSetting . createQueryBuilder ( 'notificationSetting' )
84
+ . leftJoinAndSelect (
85
+ 'notificationSetting.notificationType' ,
86
+ 'notificationType' ,
87
+ )
88
+ . where ( 'notificationSetting.id = :id' , {
89
+ id,
90
+ } )
91
+ . getOne ( ) ;
92
+ } catch ( e ) {
93
+ logger . error (
94
+ 'findNotificationSettingByNotificationTypeAndUserAddress() error' ,
95
+ e ,
96
+ ) ;
97
+ throw e ;
98
+ }
99
+ } ;
100
+
79
101
export const updateUserNotificationSetting = async ( params : {
80
102
notificationSettingId : number ;
81
103
userAddressId : number ;
82
- allowNotifications ?: string ;
83
- allowEmailNotification ?: string ;
84
- allowDappPushNotification ?: string ;
85
- } ) => {
104
+ allowEmailNotification : boolean ;
105
+ allowDappPushNotification : boolean ;
106
+ } ) : Promise < NotificationSetting > => {
86
107
const notificationSetting = await NotificationSetting . createQueryBuilder (
87
108
'notificationSetting' ,
88
109
)
@@ -102,15 +123,13 @@ export const updateUserNotificationSetting = async (params: {
102
123
if ( ! notificationSetting )
103
124
throw new Error ( errorMessages . NOTIFICATION_SETTING_NOT_FOUND ) ;
104
125
105
- if ( params . allowNotifications )
106
- notificationSetting . allowNotifications =
107
- params . allowNotifications === 'true' ;
108
- if ( params . allowEmailNotification )
109
- notificationSetting . allowEmailNotification =
110
- params . allowEmailNotification === 'true' ;
111
- if ( params . allowDappPushNotification )
126
+ if ( notificationSetting . notificationType ?. isEmailEditable ) {
127
+ notificationSetting . allowEmailNotification = params . allowEmailNotification ;
128
+ }
129
+ if ( notificationSetting . notificationType ?. isWebEditable ) {
112
130
notificationSetting . allowDappPushNotification =
113
- params . allowDappPushNotification === 'true' ;
131
+ params . allowDappPushNotification ;
132
+ }
114
133
115
134
if (
116
135
notificationSetting ?. notificationType ?. isGroupParent &&
@@ -119,7 +138,6 @@ export const updateUserNotificationSetting = async (params: {
119
138
await updateChildNotificationSettings ( {
120
139
categoryGroup : notificationSetting ?. notificationType ?. categoryGroup ,
121
140
userAddressId : params . userAddressId ,
122
- allowNotifications : notificationSetting . allowNotifications ,
123
141
allowEmailNotification : notificationSetting . allowEmailNotification ,
124
142
allowDappPushNotification : notificationSetting . allowDappPushNotification ,
125
143
} ) ;
@@ -131,9 +149,8 @@ export const updateUserNotificationSetting = async (params: {
131
149
export const updateChildNotificationSettings = async ( params : {
132
150
categoryGroup : string ;
133
151
userAddressId : number ;
134
- allowNotifications ?: boolean ;
135
- allowEmailNotification ?: boolean ;
136
- allowDappPushNotification ?: boolean ;
152
+ allowEmailNotification : boolean ;
153
+ allowDappPushNotification : boolean ;
137
154
} ) => {
138
155
// Grab type ids
139
156
const notificationTypes = await NotificationType . createQueryBuilder (
@@ -153,14 +170,12 @@ export const updateChildNotificationSettings = async (params: {
153
170
if ( notificationTypeIds . length === 0 ) return ;
154
171
155
172
await NotificationSetting . query ( `
156
- UPDATE notification_setting
157
- SET "allowNotifications" = ${
158
- params . allowNotifications
159
- } , "allowEmailNotification" = ${
160
- params . allowEmailNotification
161
- } , "allowDappPushNotification" = ${ params . allowDappPushNotification }
162
- WHERE "notificationTypeId" IN (${ notificationTypeIds . join (
163
- ',' ,
164
- ) } ) AND "userAddressId" = ${ params . userAddressId }
173
+ UPDATE notification_setting
174
+ SET "allowEmailNotification" = ${
175
+ params . allowEmailNotification
176
+ } , "allowDappPushNotification" = ${ params . allowDappPushNotification }
177
+ WHERE "notificationTypeId" IN (${ notificationTypeIds . join (
178
+ ',' ,
179
+ ) } ) AND "userAddressId" = ${ params . userAddressId }
165
180
` ) ;
166
181
} ;
0 commit comments