Add automatic random mentee show page after quick match (#931)
This commit is contained in:
parent
af4e6932fa
commit
fcb68b4f29
4 changed files with 66 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -102,22 +102,26 @@
|
|||
|
||||
<% if @user.seeking_mentorship %>
|
||||
<h2> Mentee Description </h2>
|
||||
<p style="position:sticky;top:50px;background:white;z-index:1000;padding:10px"><%= @user.mentee_description %></p>
|
||||
<p style="position:sticky;top:50px;background:white;z-index:1000;padding:15px;border:2px solid black"><%= @user.mentee_description %></p>
|
||||
|
||||
<h2> Possible Mentors </h2>
|
||||
<% count = 0 %>
|
||||
<% User.where(offering_mentorship: true).where.not(mentor_form_updated_at: nil).order("mentor_form_updated_at DESC").each do |possible_mentor| %>
|
||||
<% MentorRelationship.
|
||||
unmatched_mentors.where.not(mentor_form_updated_at: nil, id: @user.id).
|
||||
order("mentor_form_updated_at DESC").each do |possible_mentor| %>
|
||||
<% break if count > 20 %>
|
||||
<% count = count + 1 %>
|
||||
<% tag_intersection = ( @user.cached_followed_tag_names & possible_mentor.cached_followed_tag_names ) %>
|
||||
<% mentor_relationships_count = MentorRelationship.where(mentor_id: possible_mentor.id).size %>
|
||||
<% if tag_intersection.any? && mentor_relationships_count < 1 %>
|
||||
<div class="row">
|
||||
<% if tag_intersection.any? %>
|
||||
<% count = count + 1 %>
|
||||
<div class="row" style="font-size:0.9em">
|
||||
<div class="col-md-2">
|
||||
<h4>User</h4>
|
||||
<img src="<%= possible_mentor.profile_image_90 %>" style="border-radius:100px;width:50px;height:50px;" />
|
||||
<br/>
|
||||
<a href="/<%= possible_mentor.username %>" target="_blank">@<%= possible_mentor.username %></a>
|
||||
<br/>
|
||||
<a href="/intertnal/users/<%= possible_mentor.id %>" target="_blank">Internal(<%= possible_mentor.id %>)</a>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-3" style="border-left:1px solid black">
|
||||
<h4>Tag Intersection</h4>
|
||||
<%= tag_intersection.join(", ") %>
|
||||
</div>
|
||||
|
|
@ -132,6 +136,7 @@
|
|||
<div class="col-md-1">
|
||||
<h4>Action</h4>
|
||||
<%= form_for ([:internal, @user]) do |f| %>
|
||||
<%= f.hidden_field :quick_match, value: true %>
|
||||
<%= f.hidden_field :add_mentor, value: possible_mentor.id %>
|
||||
<%= f.submit "Match!" %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -31,4 +31,20 @@ RSpec.describe MentorRelationship, type: :model do
|
|||
relationship.save!
|
||||
expect(EmailMessage.all.size).to eq(2)
|
||||
end
|
||||
|
||||
it "finds unmatched mentors" do
|
||||
expect(MentorRelationship.unmatched_mentors.size).to eq(0)
|
||||
new_mentor = create(:user, mentor_form_updated_at: Time.current, offering_mentorship: true)
|
||||
expect(MentorRelationship.unmatched_mentors.size).to eq(1)
|
||||
MentorRelationship.create(mentor_id: new_mentor.id, mentee_id: mentee.id)
|
||||
expect(MentorRelationship.unmatched_mentors.size).to eq(0)
|
||||
end
|
||||
|
||||
it "finds unmatched mentees" do
|
||||
expect(MentorRelationship.unmatched_mentees.size).to eq(0)
|
||||
new_mentee = create(:user, mentee_form_updated_at: Time.current, seeking_mentorship: true)
|
||||
expect(MentorRelationship.unmatched_mentees.size).to eq(1)
|
||||
MentorRelationship.create(mentor_id: mentor.id, mentee_id: new_mentee.id)
|
||||
expect(MentorRelationship.unmatched_mentors.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue