Skip to content

Commit 63e48d9

Browse files
committed
Do not show compat score if one hasn't answered any question
1 parent 4dd6f54 commit 63e48d9

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

backend/api/src/compatible-profiles.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
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) =>

common/src/profiles/compatibility-score.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@ export const getProfilesCompatibilityFactor = (
143143
multiplier *= areLocationCompatible(profile1, profile2) ? 1 : 0.1
144144
return multiplier
145145
}
146+
147+
export const hasAnsweredQuestions = (
148+
questions: rowFor<'compatibility_answers'>[],
149+
) => {
150+
if (!questions?.length) return false
151+
for (const question of questions) {
152+
if (question.importance >= 0) return true
153+
}
154+
return false
155+
}

web/components/answers/compatibility-questions-display.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ export function CompatibilityQuestionsDisplay(props: {
119119

120120
const currentUser = useUser()
121121
const comparedUserId = fromProfilePage?.user_id ?? currentUser?.id
122-
const {compatibilityAnswers: comparedAnswers} =
123-
useUserCompatibilityAnswers(comparedUserId)
122+
const {compatibilityAnswers: comparedAnswers} = useUserCompatibilityAnswers(comparedUserId)
124123
const questionIdToComparedAnswer = keyBy(comparedAnswers, 'question_id')
125124

126125
const sortedAndFilteredAnswers = sortBy(

0 commit comments

Comments
 (0)