2020-07-13 14:55:32 +02:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-07-16 09:28:27 +02:00
|
|
|
"forge.cadoles.com/Cadoles/daddy/internal/model"
|
2020-07-13 14:55:32 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func handleUserProfile(ctx context.Context) (*model.User, error) {
|
2020-07-21 18:10:03 +02:00
|
|
|
user, _, err := getSessionUser(ctx)
|
2020-07-13 14:55:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2020-07-16 09:28:27 +02:00
|
|
|
return user, nil
|
|
|
|
}
|
2020-07-13 14:55:32 +02:00
|
|
|
|
2020-07-16 09:28:27 +02:00
|
|
|
func handleUpdateUserProfile(ctx context.Context, changes model.ProfileChanges) (*model.User, error) {
|
2020-07-21 18:10:03 +02:00
|
|
|
user, db, err := getSessionUser(ctx)
|
2020-07-16 20:21:58 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
repo := model.NewUserRepository(db)
|
|
|
|
|
|
|
|
userChanges := &model.User{}
|
|
|
|
|
|
|
|
if changes.Name != nil {
|
|
|
|
userChanges.Name = changes.Name
|
|
|
|
}
|
|
|
|
|
2020-07-21 18:10:03 +02:00
|
|
|
user, err = repo.UpdateUserByEmail(ctx, user.Email, userChanges)
|
2020-07-16 20:21:58 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return user, nil
|
2020-07-13 14:55:32 +02:00
|
|
|
}
|