William Petit
676ddf3bc8
Types: type Workgroup { id: ID! name: String createdAt: Time! closedAt: Time members: [User]! } Mutations: joinWorkgroup(workgroupId: ID!): Workgroup! leaveWorkgroup(workgroupId: ID!): Workgroup! createWorkgroup(changes: WorkgroupChanges!): Workgroup! closeWorkgroup(workgroupId: ID!): Workgroup! updateWorkgroup(workgroupId: ID!, changes: WorkgroupChanges!): Workgroup! Queries: workgroups: [Workgroup]!
40 lines
770 B
Go
40 lines
770 B
Go
package graph
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forge.cadoles.com/Cadoles/daddy/internal/model"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func handleUserProfile(ctx context.Context) (*model.User, error) {
|
|
user, _, err := getSessionUser(ctx)
|
|
if err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
return user, nil
|
|
}
|
|
|
|
func handleUpdateUserProfile(ctx context.Context, changes model.ProfileChanges) (*model.User, error) {
|
|
user, db, err := getSessionUser(ctx)
|
|
if err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
repo := model.NewUserRepository(db)
|
|
|
|
userChanges := &model.User{}
|
|
|
|
if changes.Name != nil {
|
|
userChanges.Name = changes.Name
|
|
}
|
|
|
|
user, err = repo.UpdateUserByEmail(ctx, user.Email, userChanges)
|
|
if err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
return user, nil
|
|
}
|