@@ -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 ),
@@ -8232,41 +8233,51 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
8232
8233
return database.User {},sql .ErrNoRows
8233
8234
}
8234
8235
8235
- func (q * FakeQuerier )UpdateUserNotificationPreferences (ctx context.Context ,arg database.UpdateUserNotificationPreferencesParams ) (int64 ,error ) {
8236
+ func (q * FakeQuerier )UpdateUserNotificationPreferences (_ context.Context ,arg database.UpdateUserNotificationPreferencesParams ) (int64 ,error ) {
8236
8237
err := validateDatabaseType (arg )
8237
8238
if err != nil {
8238
- return 0 ,err
8239
+ return - 1 ,err
8239
8240
}
8240
8241
8241
8242
q .mutex .Lock ()
8242
8243
defer q .mutex .Unlock ()
8243
8244
8244
8245
var upserted int64
8245
- for i , templateID := range arg .NotificationTemplateIds {
8246
+ for i := range arg .NotificationTemplateIds {
8246
8247
var (
8247
- found * database.NotificationPreference
8248
- disabled = arg .Disableds [i ]
8248
+ found bool
8249
+ templateID = arg .NotificationTemplateIds [i ]
8250
+ disabled = arg .Disableds [i ]
8249
8251
)
8250
8252
8251
- for _ ,np := range q .notificationPreferences {
8252
- if np .UserID != arg .UserID && np .NotificationTemplateID != templateID {
8253
+ for j ,np := range q .notificationPreferences {
8254
+ if np .UserID != arg .UserID {
8255
+ continue
8256
+ }
8257
+
8258
+ if np .NotificationTemplateID != templateID {
8253
8259
continue
8254
8260
}
8255
8261
8256
- found = & np
8262
+ np .Disabled = disabled
8263
+ np .UpdatedAt = time .Now ()
8264
+ q .notificationPreferences [j ]= np
8265
+
8266
+ upserted ++
8267
+ found = true
8268
+ break
8257
8269
}
8258
8270
8259
- if found != nil {
8260
- found .Disabled = disabled
8261
- found .UpdatedAt = time .Now ()
8262
- }else {
8263
- q .notificationPreferences = append (q .notificationPreferences , database.NotificationPreference {
8271
+ if ! found {
8272
+ np := database.NotificationPreference {
8264
8273
Disabled :disabled ,
8265
8274
UserID :arg .UserID ,
8266
8275
NotificationTemplateID :templateID ,
8267
8276
CreatedAt :time .Now (),
8268
8277
UpdatedAt :time .Now (),
8269
- })
8278
+ }
8279
+ q .notificationPreferences = append (q .notificationPreferences ,np )
8280
+ upserted ++
8270
8281
}
8271
8282
}
8272
8283