snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s

This commit is contained in:
upstream-mirror
2026-09-16 05:24:45 +05:00
commit cda7c1a474
272 changed files with 31973 additions and 0 deletions

30
user/update.go Normal file
View 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
}