diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb index 5f78fd47c..070231789 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb @@ -73,14 +73,19 @@ def invite_member user = MnoEnterprise::User.find_by(email: user_params[:email]) || create_unconfirmed_user(user_params) # Create the invitation - invite = @organization.org_invites.create( + invite = MnoEnterprise::OrgInvite.create( user_email: user.email, user_role: params[:user][:role], referrer_id: current_user.id, - status: 'staged' # Will be updated to 'accepted' for unconfirmed users + status: 'staged', # Will be updated to 'accepted' for unconfirmed users + organization_id: @organization.id ) - @user = user.confirmed? ? invite : user.reload + if invite.persisted? + @user = user.confirmed? ? invite : user.reload + else + render json: invite.errors, status: :bad_request + end end protected diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb index 882183970..50b5524dc 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb @@ -157,7 +157,7 @@ def partial_hash_for_arrears(arrear) # Track the api call @api_call = false stub = -> { @api_call = true; from_api(org_invite) } - api_stub_for(post: "/organizations/#{organization.id}/org_invites", response: stub) + api_stub_for(post: "/org_invites", response: stub) end let(:params) { FactoryGirl.attributes_for(:user) }