Просмотр исходного кода

CustomerCreate

- enhance GetUserCount
Alexey Kim 2 лет назад
Родитель
Сommit
b7251b4a62
1 измененных файлов с 7 добавлено и 6 удалено
  1. 7 6
      graphql/mutationCustomerCreate.go

+ 7 - 6
graphql/mutationCustomerCreate.go

@@ -41,14 +41,15 @@ func (r *mutationResolver) CustomerCreate(
 		return response, err
 	}
 
-	if ls, err := r.client.GetUsers(ctx, admin.AccessToken, r.conf.Cli.Realm, gocloak.GetUsersParams{
+	if count, err := r.client.GetUserCount(ctx, admin.AccessToken, r.conf.Cli.Realm, gocloak.GetUsersParams{
 		Email: gocloak.StringP(input.Email),
-	}); err != nil {
-		response.CustomerUserErrors = append(response.CustomerUserErrors,
-			CustomerError(generated.CustomerErrorCodeBlank, err))
-	} else if len(ls) > 0 {
+	}); err != nil || count > 0 {
+		if count > 0 {
+			err = fmt.Errorf("email has been already registered")
+		}
+
 		response.CustomerUserErrors = append(response.CustomerUserErrors,
-			CustomerError(generated.CustomerErrorCodeTaken, fmt.Errorf("email has been already registered"), "email"))
+			CustomerError(generated.CustomerErrorCodeTaken, err, "email"))
 	}
 
 	if len(response.CustomerUserErrors) > 0 {