diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index 716528f2d..2a6408afc 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -17,7 +17,11 @@ class Internal::UsersController < Internal::ApplicationController end def show - @user = User.find(params[:id]) + if params[:id] == "unmatched_mentee" + @user = MentorRelationship.unmatched_mentees.order("RANDOM()").first + else + @user = User.find(params[:id]) + end @user_mentee_relationships = MentorRelationship.where(mentor_id: @user.id) @user_mentor_relationships = MentorRelationship.where(mentee_id: @user.id) end @@ -29,7 +33,11 @@ class Internal::UsersController < Internal::ApplicationController handle_mentorship add_note @user.update!(user_params) - redirect_to "/internal/users/#{@user.id}" + if params[:quick_match] + redirect_to "/internal/users/unmatched_mentee" + else + redirect_to "/internal/users/#{@user.id}" + end end def handle_mentorship diff --git a/app/models/mentor_relationship.rb b/app/models/mentor_relationship.rb index 946c6fd2f..c7215eadc 100644 --- a/app/models/mentor_relationship.rb +++ b/app/models/mentor_relationship.rb @@ -15,6 +15,33 @@ class MentorRelationship < ApplicationRecord end end + def self.unmatched_mentees + sql = "SELECT mentee_form_updated_at, + users.id, + mentor_relationships.mentor_id + FROM users + LEFT JOIN notes ON users.id = notes.noteable_id + LEFT JOIN mentor_relationships ON users.id = mentor_relationships.mentee_id + WHERE seeking_mentorship IS TRUE + AND mentor_relationships.mentor_id IS null" + record_ids = ActiveRecord::Base.connection.execute(sql).pluck("id") + User.where(id: record_ids) + end + + def self.unmatched_mentors + sql = "SELECT mentor_form_updated_at, + users.id, + mentor_relationships.mentor_id + FROM users + LEFT JOIN notes ON users.id = notes.noteable_id + LEFT JOIN mentor_relationships ON users.id = mentor_relationships.mentor_id + WHERE offering_mentorship IS TRUE + AND mentor_relationships.mentee_id IS null" + record_ids = ActiveRecord::Base.connection.execute(sql).pluck("id") + User.where(id: record_ids) + end + + private def mutual_follow diff --git a/app/views/internal/users/show.html.erb b/app/views/internal/users/show.html.erb index 0eca10565..08186521e 100644 --- a/app/views/internal/users/show.html.erb +++ b/app/views/internal/users/show.html.erb @@ -102,22 +102,26 @@ <% if @user.seeking_mentorship %>
<%= @user.mentee_description %>
+<%= @user.mentee_description %>