@@ -8,60 +8,48 @@ Deno.serve(async (req) => {
88 if ( ! user ) {
99 return Response . json ( { error : 'Unauthorized' } , { status : 401 } ) ;
1010 }
11-
12- const { user_email, skills_to_learn } = await req . json ( ) ;
13- const targetEmail = user_email || user . email ;
14-
15- // Get user's profile
16- const userProfile = await base44 . entities . UserProfile . filter ( {
17- user_email : targetEmail
18- } ) ;
19-
20- if ( ! userProfile [ 0 ] ) {
21- return Response . json ( { error : 'User profile not found' } , { status : 404 } ) ;
11+
12+ const { menteeEmail } = await req . json ( ) ;
13+
14+ // Fetch mentee profile
15+ const [ menteeProfile ] = await base44 . entities . UserProfile . filter ( { user_email : menteeEmail } ) ;
16+
17+ if ( ! menteeProfile ) {
18+ return Response . json ( { error : 'Mentee profile not found' } , { status : 404 } ) ;
2219 }
23-
24- // Get all potential mentors (users with expertise)
25- const allProfiles = await base44 . asServiceRole . entities . UserProfile . filter ( {
26- user_email : { $ne : targetEmail }
27- } ) ;
28-
20+
21+ // Fetch all potential mentors (experienced users)
22+ const allProfiles = await base44 . asServiceRole . entities . UserProfile . filter ( { } ) ;
2923 const potentialMentors = allProfiles . filter ( p =>
30- p . expertise_areas && p . expertise_areas . length > 0
24+ p . user_email !== menteeEmail &&
25+ ( p . skills ?. length || 0 ) >= 5 &&
26+ new Date ( p . start_date ) < new Date ( menteeProfile . start_date )
3127 ) ;
28+
29+ // Use AI to analyze best matches
30+ const analysisPrompt = `Analyze mentor-mentee compatibility for employee onboarding:
3231
33- // Use AI to match mentors
34- const matches = await base44 . integrations . Core . InvokeLLM ( {
35- prompt : `Match this user with the best internal mentors:
36-
37- USER SEEKING MENTORSHIP:
38- Email: ${ targetEmail }
39- Department: ${ userProfile [ 0 ] . department || 'N/A' }
40- Job Title: ${ userProfile [ 0 ] . job_title || 'N/A' }
41- Current Skills: ${ userProfile [ 0 ] . skill_levels ?. map ( s => `${ s . skill } (${ s . level } )` ) . join ( ', ' ) || 'None' }
42- Skills to Learn: ${ skills_to_learn ?. join ( ', ' ) || userProfile [ 0 ] . skill_interests ?. join ( ', ' ) || 'General growth' }
43- Learning Goals: ${ userProfile [ 0 ] . learning_goals ?. join ( ', ' ) || 'N/A' }
32+ Mentee Profile:
33+ - Email: ${ menteeEmail }
34+ - Role: ${ menteeProfile . role || 'Not specified' }
35+ - Department: ${ menteeProfile . department || 'Not specified' }
36+ - Skills: ${ menteeProfile . skills ?. map ( s => s . skill_name ) . join ( ', ' ) || 'None listed' }
37+ - Interests: ${ menteeProfile . interests ?. join ( ', ' ) || 'None listed' }
38+ - Career aspirations: ${ menteeProfile . career_aspirations || 'Not specified' }
4439
45- POTENTIAL MENTORS (${ potentialMentors . length } available ):
46- ${ potentialMentors . slice ( 0 , 20 ) . map ( p => `
47- - ${ p . user_email }
48- Department : ${ p . department || 'N/A ' }
49- Job Title : ${ p . job_title || 'N/A ' }
50- Expertise : ${ p . expertise_areas ? .join ( ', ' ) || 'None' }
51- Skills : ${ p . skill_levels ?. map ( s => ` ${ s . skill } ( ${ s . level } )` ) . join ( ', ' ) || 'None' }
40+ Potential Mentors (${ potentialMentors . length } ):
41+ ${ potentialMentors . slice ( 0 , 10 ) . map ( ( p , i ) => `
42+ ${ i + 1 } . ${ p . user_email }
43+ Role : ${ p . role || 'Unknown ' }
44+ Department : ${ p . department || 'Unknown ' }
45+ Skills : ${ p . skills ?. map ( s => s . skill_name ) . join ( ', ' ) || 'None' }
46+ Experience : ${ p . career_history ?. length || 0 } positions
5247` ) . join ( '\n' ) }
5348
54- Find the top 5 best mentor matches considering:
55- 1. Expertise alignment with learning goals
56- 2. Department/role relevance
57- 3. Skill level compatibility (mentor should be advanced in areas user wants to learn)
58-
59- For each match provide:
60- - mentor_email
61- - match_score (0-100)
62- - matching_skills (array of overlapping skills)
63- - mentorship_areas (what they can teach)
64- - reasoning (why this is a good match)` ,
49+ Return the top 3 mentor matches with scores and reasoning.` ;
50+
51+ const matches = await base44 . integrations . Core . InvokeLLM ( {
52+ prompt : analysisPrompt ,
6553 response_json_schema : {
6654 type : "object" ,
6755 properties : {
@@ -72,24 +60,47 @@ For each match provide:
7260 properties : {
7361 mentor_email : { type : "string" } ,
7462 match_score : { type : "number" } ,
75- matching_skills : { type : "array" , items : { type : "string" } } ,
76- mentorship_areas : { type : "array" , items : { type : "string" } } ,
77- reasoning : { type : "string" }
63+ skill_overlap_score : { type : "number" } ,
64+ department_alignment : { type : "boolean" } ,
65+ reasoning : { type : "string" } ,
66+ suggested_goals : {
67+ type : "array" ,
68+ items : { type : "string" }
69+ }
7870 }
7971 }
8072 }
8173 }
8274 }
8375 } ) ;
84-
76+
77+ // Save top matches to database
78+ for ( const match of matches . matches . slice ( 0 , 3 ) ) {
79+ const existing = await base44 . entities . MentorMatch . filter ( {
80+ mentor_email : match . mentor_email ,
81+ mentee_email : menteeEmail
82+ } ) ;
83+
84+ if ( existing . length === 0 ) {
85+ await base44 . asServiceRole . entities . MentorMatch . create ( {
86+ mentor_email : match . mentor_email ,
87+ mentee_email : menteeEmail ,
88+ match_score : match . match_score ,
89+ matching_criteria : {
90+ skill_overlap : match . skill_overlap_score ,
91+ department_alignment : match . department_alignment
92+ } ,
93+ status : 'suggested' ,
94+ goals : match . suggested_goals ?. map ( g => ( { goal : g , progress : 0 } ) ) || [ ]
95+ } ) ;
96+ }
97+ }
98+
8599 return Response . json ( {
86100 success : true ,
87- user_email : targetEmail ,
88101 matches : matches . matches
89102 } ) ;
90-
91103 } catch ( error ) {
92- console . error ( 'Mentor matching error:' , error ) ;
93104 return Response . json ( { error : error . message } , { status : 500 } ) ;
94105 }
95106} ) ;
0 commit comments