summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-24 20:34:23 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-24 20:34:23 -0600
commita4e461bccee482c40e69be9310ba12de5d7da59b (patch)
tree393c62df15091d88083ad4841d95e9d0083534c3 /app/controllers/api
parent92994313506152f366d91f845aa1ff59e84b0acd (diff)
Fixes de addresses_controller
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/addresses_controller.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/app/controllers/api/addresses_controller.rb b/app/controllers/api/addresses_controller.rb
index 4eda02d..ebe129b 100644
--- a/app/controllers/api/addresses_controller.rb
+++ b/app/controllers/api/addresses_controller.rb
@@ -12,8 +12,13 @@ module Api
def create
@service = Services::CreateAddressService.new(current_user_account, service_params)
- unless @service.call
- render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity
+ begin
+ unless @service.call
+ render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity
+ return
+ end
+ rescue ActiveRecord::RecordNotUnique
+ render json: { error_message: 'Ya cuenta con esta dirección' }, status: :unprocessable_entity
return
end
@@ -55,7 +60,7 @@ module Api
end
def service_params
- params.require(:number, :street, :zip_code, :country, :city)
+ params.permit(:number, :street, :zip_code, :country, :city)
end
end
end