summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/addresses_controller.rb4
-rw-r--r--app/controllers/api/cards_controller.rb4
-rw-r--r--app/controllers/api/companies_controller.rb4
-rw-r--r--app/controllers/api/products_controller.rb4
-rw-r--r--app/controllers/api/sessions_controller.rb2
-rw-r--r--app/controllers/api/user_accounts_controller.rb4
-rw-r--r--app/services/addresses/address_services_base.rb4
7 files changed, 15 insertions, 11 deletions
diff --git a/app/controllers/api/addresses_controller.rb b/app/controllers/api/addresses_controller.rb
index 386e613..51b6b99 100644
--- a/app/controllers/api/addresses_controller.rb
+++ b/app/controllers/api/addresses_controller.rb
@@ -14,7 +14,7 @@ module Api
begin
unless @service.call
- render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @service.error_messages }, status: :unprocessable_entity
return
end
rescue ActiveRecord::RecordNotUnique
@@ -34,7 +34,7 @@ module Api
when :not_found
render status: :not_found
when :unprocessable_entity
- render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @service.error_messages }, status: :unprocessable_entity
else
@address = @service.address
render json: serialized_object.serializable_hash, status: :ok
diff --git a/app/controllers/api/cards_controller.rb b/app/controllers/api/cards_controller.rb
index 41d6138..daf5f3a 100644
--- a/app/controllers/api/cards_controller.rb
+++ b/app/controllers/api/cards_controller.rb
@@ -16,7 +16,7 @@ module Api
if @card.save
render json: serialized_object.serializable_hash, status: :ok
else
- render json: { error_messages: @card.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @card.errors.as_json }, status: :unprocessable_entity
end
end
@@ -28,7 +28,7 @@ module Api
if @card.update(permitted_params)
render json: serialized_object.serializable_hash, status: :ok
else
- render json: { error_messages: @card.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @card.errors.as_json }, status: :unprocessable_entity
end
end
diff --git a/app/controllers/api/companies_controller.rb b/app/controllers/api/companies_controller.rb
index 19e3493..4c19716 100644
--- a/app/controllers/api/companies_controller.rb
+++ b/app/controllers/api/companies_controller.rb
@@ -22,7 +22,7 @@ module Api
render json: serialized_object.serializable_hash, status: :ok and return if @company.save
- render json: { error_messages: @company.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @company.errors.as_json }, status: :unprocessable_entity
end
def update
@@ -33,7 +33,7 @@ module Api
if @company.update(permitted_params)
render json: serialized_object.serializable_hash, status: :ok
else
- render json: { error_messages: @company.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @company.errors.as_json }, status: :unprocessable_entity
end
end
diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb
index 5ebd6b6..2fa435d 100644
--- a/app/controllers/api/products_controller.rb
+++ b/app/controllers/api/products_controller.rb
@@ -21,7 +21,7 @@ module Api
if @product.save
render json: serialized_object(@product.public_id).serializable_hash, status: :ok
else
- render json: { error_messages: @product.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @product.errors.as_json }, status: :unprocessable_entity
end
end
@@ -33,7 +33,7 @@ module Api
if @product.update(object_params)
render json: serialized_object(@product.public_id).serializable_hash, status: :ok
else
- render json: { error_messages: @product.errors.full_messages }, status: :unprocessable_entity
+ render json: { errors: @product.errors.as_json }, status: :unprocessable_entity
end
end
diff --git a/app/controllers/api/sessions_controller.rb b/app/controllers/api/sessions_controller.rb
index 3d9f315..a81af71 100644
--- a/app/controllers/api/sessions_controller.rb
+++ b/app/controllers/api/sessions_controller.rb
@@ -9,7 +9,7 @@ module Api
@user_account = UserAccount.find_by(email: permitted_params[:email])
unless @user_account&.authenticate(permitted_params[:password])
- render json: { error_message: 'Credenciales incorrectas' }, status: :unauthorized and return
+ render json: { errors: { auth: 'Credenciales incorrectas' } }, status: :unauthorized and return
end
render json: generate_token, status: :ok
diff --git a/app/controllers/api/user_accounts_controller.rb b/app/controllers/api/user_accounts_controller.rb
index ad276b5..6404dee 100644
--- a/app/controllers/api/user_accounts_controller.rb
+++ b/app/controllers/api/user_accounts_controller.rb
@@ -14,14 +14,14 @@ module Api
render json: generate_token, status: :ok and return if @user_account.save
- render json: @user_account.errors.full_messages, status: :unprocessable_entity
+ render json: { errors: @user_account.errors.as_json }, status: :unprocessable_entity
end
def update
if current_user_account.update(permitted_params)
render json: serialized_object.serializable_hash, status: :ok
else
- render json: current_user_account.errors.full_messages, status: :unprocessable_entity
+ render json: { errors: current_user_account.errors.as_json }, status: :unprocessable_entity
end
end
diff --git a/app/services/addresses/address_services_base.rb b/app/services/addresses/address_services_base.rb
index 06ffde7..9b7f9f3 100644
--- a/app/services/addresses/address_services_base.rb
+++ b/app/services/addresses/address_services_base.rb
@@ -8,6 +8,10 @@ module Addresses
@params = params
end
+ def error_messages
+ @address.errors.as_json
+ end
+
private
def already_existing_address