summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-10 20:12:55 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-10 20:12:55 -0600
commit5faf9807968ce9f7f548474afdc31029e57103dc (patch)
treee0c2fc55cfd9908e503897304beed8c718921f2c /app/controllers/api
parent8f04e87b466e79fa2086d69d9c49f5af89b68cb9 (diff)
Añade método update al controlador de companies
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/companies_controller.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/controllers/api/companies_controller.rb b/app/controllers/api/companies_controller.rb
index 4317682..9d6cb1c 100644
--- a/app/controllers/api/companies_controller.rb
+++ b/app/controllers/api/companies_controller.rb
@@ -17,7 +17,7 @@ module Api
render json: serialized_object.serializable_hash, status: :ok and return if @company
- render json: { error_message: "No se encontró la compañía #{params[:short_name]}" }, status: :not_found
+ render json: not_found_error_message, status: :not_found
end
def create
@@ -28,6 +28,18 @@ module Api
render json: { error_messages: @company.errors.full_messages }, status: :unprocessable_entity
end
+ def update
+ @company = Company.find_by(short_name: params[:id])
+
+ render json: not_found_error_message, status: :not_found and return if @company.nil?
+
+ 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
+ end
+ end
+
private
def serialized_object
@@ -41,5 +53,9 @@ module Api
def permitted_params
params.permit(:name, :country, :short_name, :logo)
end
+
+ def not_found_error_message
+ { error_message: "No se encontró la compañía #{params[:short_name]}"}
+ end
end
end