1- import { groupBy , sortBy } from 'lodash'
2- import { APIError , type APIHandler } from 'api/helpers/endpoint'
3- import { getCompatibilityScore } from 'common/profiles/compatibility-score'
4- import {
5- getProfile ,
6- getCompatibilityAnswers ,
7- getGenderCompatibleProfiles ,
8- } from 'shared/profiles/supabase'
9- import { log } from 'shared/utils'
10-
11- export const getCompatibleProfilesHandler : APIHandler <
12- 'compatible-profiles'
13- > = async ( props ) => {
14- return getCompatibleProfiles ( props . userId )
1+ import { groupBy , sortBy } from 'lodash'
2+ import { APIError , type APIHandler } from 'api/helpers/endpoint'
3+ import { getCompatibilityScore , hasAnsweredQuestions } from 'common/profiles/compatibility-score'
4+ import { getCompatibilityAnswers , getGenderCompatibleProfiles , getProfile , } from 'shared/profiles/supabase'
5+ import { log } from 'shared/utils'
6+
7+ export const getCompatibleProfilesHandler : APIHandler < 'compatible-profiles' > = async ( props ) => {
8+ return getCompatibleProfiles ( props . userId , false )
159}
1610
17- export const getCompatibleProfiles = async ( userId : string ) => {
11+ export const getCompatibleProfiles = async (
12+ userId : string ,
13+ includeProfilesWithoutPromptAnswers : boolean = true ,
14+ ) => {
1815 const profile = await getProfile ( userId )
1916
2017 log ( 'got profile' , {
@@ -25,7 +22,7 @@ export const getCompatibleProfiles = async (userId: string) => {
2522
2623 if ( ! profile ) throw new APIError ( 404 , 'Profile not found' )
2724
28- const profiles = await getGenderCompatibleProfiles ( profile )
25+ let profiles = await getGenderCompatibleProfiles ( profile )
2926
3027 const profileAnswers = await getCompatibilityAnswers ( [
3128 userId ,
@@ -34,6 +31,10 @@ export const getCompatibleProfiles = async (userId: string) => {
3431 log ( 'got profile answers ' + profileAnswers . length )
3532
3633 const answersByUserId = groupBy ( profileAnswers , 'creator_id' )
34+ if ( ! includeProfilesWithoutPromptAnswers ) {
35+ profiles = profiles . filter ( ( l ) => hasAnsweredQuestions ( answersByUserId [ l . user_id ] ) )
36+ if ( ! hasAnsweredQuestions ( answersByUserId [ profile . user_id ] ) ) profiles = [ ]
37+ }
3738 const profileCompatibilityScores = Object . fromEntries (
3839 profiles . map (
3940 ( l ) =>
0 commit comments