@@ -65,6 +65,7 @@ func New() database.Store {
65
65
files : make ([]database.File , 0 ),
66
66
gitSSHKey : make ([]database.GitSSHKey , 0 ),
67
67
notificationMessages : make ([]database.NotificationMessage , 0 ),
68
+ notificationPreferences : make ([]database.NotificationPreference , 0 ),
68
69
parameterSchemas : make ([]database.ParameterSchema , 0 ),
69
70
provisionerDaemons : make ([]database.ProvisionerDaemon , 0 ),
70
71
workspaceAgents : make ([]database.WorkspaceAgent , 0 ),
@@ -8143,41 +8144,51 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
8143
8144
return database.User {}, sql .ErrNoRows
8144
8145
}
8145
8146
8146
- func (q * FakeQuerier ) UpdateUserNotificationPreferences (ctx context.Context , arg database.UpdateUserNotificationPreferencesParams ) (int64 , error ) {
8147
+ func (q * FakeQuerier ) UpdateUserNotificationPreferences (_ context.Context , arg database.UpdateUserNotificationPreferencesParams ) (int64 , error ) {
8147
8148
err := validateDatabaseType (arg )
8148
8149
if err != nil {
8149
- return 0 , err
8150
+ return - 1 , err
8150
8151
}
8151
8152
8152
8153
q .mutex .Lock ()
8153
8154
defer q .mutex .Unlock ()
8154
8155
8155
8156
var upserted int64
8156
- for i , templateID := range arg .NotificationTemplateIds {
8157
+ for i := range arg .NotificationTemplateIds {
8157
8158
var (
8158
- found * database.NotificationPreference
8159
- disabled = arg .Disableds [i ]
8159
+ found bool
8160
+ templateID = arg .NotificationTemplateIds [i ]
8161
+ disabled = arg .Disableds [i ]
8160
8162
)
8161
8163
8162
- for _ , np := range q .notificationPreferences {
8163
- if np .UserID != arg .UserID && np .NotificationTemplateID != templateID {
8164
+ for j , np := range q .notificationPreferences {
8165
+ if np .UserID != arg .UserID {
8166
+ continue
8167
+ }
8168
+
8169
+ if np .NotificationTemplateID != templateID {
8164
8170
continue
8165
8171
}
8166
8172
8167
- found = & np
8173
+ np .Disabled = disabled
8174
+ np .UpdatedAt = time .Now ()
8175
+ q .notificationPreferences [j ] = np
8176
+
8177
+ upserted ++
8178
+ found = true
8179
+ break
8168
8180
}
8169
8181
8170
- if found != nil {
8171
- found .Disabled = disabled
8172
- found .UpdatedAt = time .Now ()
8173
- } else {
8174
- q .notificationPreferences = append (q .notificationPreferences , database.NotificationPreference {
8182
+ if ! found {
8183
+ np := database.NotificationPreference {
8175
8184
Disabled : disabled ,
8176
8185
UserID : arg .UserID ,
8177
8186
NotificationTemplateID : templateID ,
8178
8187
CreatedAt : time .Now (),
8179
8188
UpdatedAt : time .Now (),
8180
- })
8189
+ }
8190
+ q .notificationPreferences = append (q .notificationPreferences , np )
8191
+ upserted ++
8181
8192
}
8182
8193
}
8183
8194
0 commit comments