snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
30
user/update.go
Normal file
30
user/update.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// UpdateUser updates a user.
|
||||
func (r *ResolverForUser) UpdateUser(ctx context.Context, id int, name string, pass *string, admin bool) (*gqlmodel.User, error) {
|
||||
user := new(model.User)
|
||||
if r.DB.Find(user, id).RecordNotFound() {
|
||||
return nil, fmt.Errorf("user with id %d does not exist", id)
|
||||
}
|
||||
|
||||
user.Name = name
|
||||
user.Admin = admin
|
||||
|
||||
if pass != nil {
|
||||
user.Pass = createPassword(*pass, r.PassStrength)
|
||||
}
|
||||
|
||||
update := r.DB.Save(user)
|
||||
gqlUser := &gqlmodel.User{}
|
||||
copier.Copy(gqlUser, user)
|
||||
return gqlUser, update.Error
|
||||
}
|
||||
Reference in New Issue
Block a user