Skip to content

Commit

Permalink
Improve account registration resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
demdxx committed Mar 29, 2024
1 parent dfd462c commit 799dee2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions repository/account/delivery/graphql/base_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ var (

// QueryResolver implements GQL API methods
type QueryResolver struct {
userRepo *userrepo.Repository
accounts account.Usecase
}

// NewQueryResolver returns new API resolver
func NewQueryResolver() *QueryResolver {
return &QueryResolver{
userRepo: userrepo.New(),
accounts: usecase.NewAccountUsecase(userrepo.New(), repository.New()),
}
}
Expand Down Expand Up @@ -85,22 +87,22 @@ func (r *QueryResolver) RegisterAccount(ctx context.Context, input *gqlmodels.Ac

if _, err := r.accounts.Register(ctx, userObj, accObj, input.Password); err != nil {
return nil, err
} else {
userObj, _ = r.userRepo.Get(ctx, userObj.ID)
}

// Send message to the account owner about the account creation (welcome message)
err := messanger.Get(ctx).Send(ctx,
"account.register",
[]string{userObj.Email},
map[string]any{
err := messanger.Get(ctx).Send(ctx, "account.register",
[]string{userObj.Email}, map[string]any{
"id": accObj.ID,
"account": accObj,
"owner": userObj,
})
if err != nil {
// Log error if message sending failed but do not return error to the client
ctxlogger.Get(ctx).Error("Failed to send message",
zap.String("template", "account.created"),
zap.String("template", "account.register"),
zap.Error(err))
return nil, err
}

return &gqlmodels.AccountCreatePayload{
Expand Down

0 comments on commit 799dee2

Please sign in to comment.