@@ -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 ),
@@ -8123,41 +8124,51 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
8123
8124
return database.User {},sql .ErrNoRows
8124
8125
}
8125
8126
8126
- func (q * FakeQuerier )UpdateUserNotificationPreferences (ctx context.Context ,arg database.UpdateUserNotificationPreferencesParams ) (int64 ,error ) {
8127
+ func (q * FakeQuerier )UpdateUserNotificationPreferences (_ context.Context ,arg database.UpdateUserNotificationPreferencesParams ) (int64 ,error ) {
8127
8128
err := validateDatabaseType (arg )
8128
8129
if err != nil {
8129
- return 0 ,err
8130
+ return - 1 ,err
8130
8131
}
8131
8132
8132
8133
q .mutex .Lock ()
8133
8134
defer q .mutex .Unlock ()
8134
8135
8135
8136
var upserted int64
8136
- for i , templateID := range arg .NotificationTemplateIds {
8137
+ for i := range arg .NotificationTemplateIds {
8137
8138
var (
8138
- found * database.NotificationPreference
8139
- disabled = arg .Disableds [i ]
8139
+ found bool
8140
+ templateID = arg .NotificationTemplateIds [i ]
8141
+ disabled = arg .Disableds [i ]
8140
8142
)
8141
8143
8142
- for _ ,np := range q .notificationPreferences {
8143
- if np .UserID != arg .UserID && np .NotificationTemplateID != templateID {
8144
+ for j ,np := range q .notificationPreferences {
8145
+ if np .UserID != arg .UserID {
8146
+ continue
8147
+ }
8148
+
8149
+ if np .NotificationTemplateID != templateID {
8144
8150
continue
8145
8151
}
8146
8152
8147
- found = & np
8153
+ np .Disabled = disabled
8154
+ np .UpdatedAt = time .Now ()
8155
+ q .notificationPreferences [j ]= np
8156
+
8157
+ upserted ++
8158
+ found = true
8159
+ break
8148
8160
}
8149
8161
8150
- if found != nil {
8151
- found .Disabled = disabled
8152
- found .UpdatedAt = time .Now ()
8153
- }else {
8154
- q .notificationPreferences = append (q .notificationPreferences , database.NotificationPreference {
8162
+ if ! found {
8163
+ np := database.NotificationPreference {
8155
8164
Disabled :disabled ,
8156
8165
UserID :arg .UserID ,
8157
8166
NotificationTemplateID :templateID ,
8158
8167
CreatedAt :time .Now (),
8159
8168
UpdatedAt :time .Now (),
8160
- })
8169
+ }
8170
+ q .notificationPreferences = append (q .notificationPreferences ,np )
8171
+ upserted ++
8161
8172
}
8162
8173
}
8163
8174