aboutsummaryrefslogtreecommitdiff
path: root/user/service.go
diff options
context:
space:
mode:
Diffstat (limited to 'user/service.go')
-rw-r--r--user/service.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/user/service.go b/user/service.go
index 4544cb4..222df4a 100644
--- a/user/service.go
+++ b/user/service.go
@@ -1,5 +1,5 @@
/* openbills - Server for web based Libre Billing Software
- * Copyright (C) 2023 Vidhu Kant Sharma <vidhukant@vidhukant.com>
+ * Copyright (C) 2023-2024 Vidhu Kant Sharma <vidhukant@vidhukant.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -75,3 +75,22 @@ func (u *User) del() error {
return nil
}
+
+func (u *User) update(changes map[string]interface{}) error {
+ res := db.Model(&u).
+ Omit("email").
+ Omit("password").
+ Omit("username").
+ Updates(changes)
+
+ // TODO: handle potential errors
+ if res.Error != nil {
+ return res.Error
+ }
+
+ if res.RowsAffected == 0 {
+ return e.ErrNotFound
+ }
+
+ return nil
+}