Commit 6f6e42f3 authored by Matheus Horstmann's avatar Matheus Horstmann 🐴

Merge branch 'check_professional_roles' into 'develop'

Check roles on creating professional

See merge request !85
parents 4d70ae81 c6a1e1cc
Pipeline #17354 passed with stages
in 1 minute and 22 seconds
......@@ -103,6 +103,16 @@ module Api::V1
success = false
error_message = nil
# Check if the roles list is not empty, if it is, displays
# an error message
if params[:professional][:roles].blank?
render json: {
# errors: ["You must inform at least one role!"]
errors: ["É necessário informar pelo menos uma permissão!"]
}, status: 422
return
end
raise_rollback = -> (error) {
error_message = error
raise ActiveRecord::Rollback
......@@ -144,7 +154,6 @@ module Api::V1
@citizen.account_id = @account.id
raise_rollback.call(@citizen.errors.to_hash) unless @citizen.save
# Creates professional
@professional = Professional.new(professional_params)
......@@ -152,8 +161,9 @@ module Api::V1
@professional.active = true
raise_rollback.call(@professional.errors.to_hash) unless @professional.save
# Professional service places list
psp_id_list = []
# Creates professionals service places
params[:professional][:roles].each do |item|
psp = ProfessionalsServicePlace.new({
......
......@@ -101,7 +101,7 @@ class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
end
it "should not be permitted" do
assert_equal 404, response.status
assert_equal 422, response.status
end
it "should not create a professional" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment