Skip to content

Commit cdbc9c3

Browse files
committed
Allow null for profiles
1 parent cdbce13 commit cdbc9c3

File tree

7 files changed

+73
-69
lines changed

7 files changed

+73
-69
lines changed

backend/api/src/get-profiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const loadProfiles = async (props: profileQueryType) => {
8989
const profiles = compatibleProfiles.filter(
9090
(l) =>
9191
(!name || l.user.name.toLowerCase().includes(name.toLowerCase())) &&
92-
(!genders || genders.includes(l.gender)) &&
92+
(!genders || genders.includes(l.gender ?? '')) &&
9393
(!education_levels || education_levels.includes(l.education_level ?? '')) &&
9494
(!pref_gender || intersection(pref_gender, l.pref_gender).length) &&
9595
(!pref_age_min || (l.age ?? MAX_INT) >= pref_age_min) &&

backend/shared/src/profiles/parse-photos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const removePinnedUrlFromPhotoUrls = async (parsedBody: {
22
pinned_url?: string
3-
photo_urls?: string[]
3+
photo_urls?: string[] | null
44
}) => {
55
if (parsedBody.photo_urls && parsedBody.pinned_url) {
66
parsedBody.photo_urls = parsedBody.photo_urls.filter(

common/src/api/zod-types.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,56 @@ export const zBoolean = z
4747
.transform((val) => val === true || val === "true");
4848

4949
export const baseProfilesSchema = z.object({
50-
age: z.number().min(18).max(100).optional(),
50+
age: z.number().min(18).max(100).optional().nullable(),
5151
bio: contentSchema.optional().nullable(),
5252
bio_length: z.number().optional().nullable(),
5353
city: z.string(),
54-
city_latitude: z.number().optional(),
55-
city_longitude: z.number().optional(),
56-
country: z.string().optional(),
54+
city_latitude: z.number().optional().nullable(),
55+
city_longitude: z.number().optional().nullable(),
56+
country: z.string().optional().nullable(),
5757
gender: genderType,
58-
geodb_city_id: z.string().optional(),
58+
geodb_city_id: z.string().optional().nullable(),
5959
looking_for_matches: zBoolean,
60-
photo_urls: z.array(z.string()),
60+
photo_urls: z.array(z.string()).nullable(),
6161
pinned_url: z.string(),
62-
pref_age_max: z.number().min(18).max(100).optional(),
63-
pref_age_min: z.number().min(18).max(100).optional(),
64-
pref_gender: genderTypes,
65-
pref_relation_styles: z.array(z.string()),
66-
referred_by_username: z.string().optional(),
67-
region_code: z.string().optional(),
62+
pref_age_max: z.number().min(18).max(100).optional().nullable(),
63+
pref_age_min: z.number().min(18).max(100).optional().nullable(),
64+
pref_gender: genderTypes.nullable(),
65+
pref_relation_styles: z.array(z.string()).nullable(),
66+
referred_by_username: z.string().optional().nullable(),
67+
region_code: z.string().optional().nullable(),
6868
visibility: z.union([z.literal('public'), z.literal('member')]),
69-
wants_kids_strength: z.number(),
69+
wants_kids_strength: z.number().nullable(),
7070
})
7171

7272
const optionalProfilesSchema = z.object({
73-
avatar_url: z.string().optional(),
73+
avatar_url: z.string().optional().nullable(),
7474
bio: contentSchema.optional().nullable(),
75-
born_in_location: z.string().optional(),
75+
born_in_location: z.string().optional().nullable(),
7676
comments_enabled: zBoolean.optional(),
77-
company: z.string().optional(),
78-
diet: z.array(z.string()).optional(),
77+
company: z.string().optional().nullable(),
78+
diet: z.array(z.string()).optional().nullable(),
7979
disabled: zBoolean.optional(),
80-
drinks_max: z.number().min(0).optional(),
81-
drinks_min: z.number().min(0).optional(),
82-
drinks_per_month: z.number().min(0).optional(),
83-
education_level: z.string().optional(),
84-
ethnicity: z.array(z.string()).optional(),
85-
has_kids: z.number().min(0).optional(),
86-
has_pets: zBoolean.optional(),
87-
height_in_inches: z.number().optional(),
88-
is_smoker: zBoolean.optional(),
89-
occupation: z.string().optional(),
90-
occupation_title: z.string().optional(),
91-
political_beliefs: z.array(z.string()).optional(),
92-
political_details: z.string().optional(),
93-
pref_romantic_styles: z.array(z.string()),
94-
religion: z.array(z.string()).optional(),
95-
religious_belief_strength: z.number().optional(),
96-
religious_beliefs: z.string().optional(),
97-
twitter: z.string().optional(),
98-
university: z.string().optional(),
99-
website: z.string().optional(),
80+
drinks_max: z.number().min(0).optional().nullable(),
81+
drinks_min: z.number().min(0).optional().nullable(),
82+
drinks_per_month: z.number().min(0).optional().nullable(),
83+
education_level: z.string().optional().nullable(),
84+
ethnicity: z.array(z.string()).optional().nullable(),
85+
has_kids: z.number().min(0).optional().nullable(),
86+
has_pets: zBoolean.optional().nullable(),
87+
height_in_inches: z.number().optional().nullable(),
88+
is_smoker: zBoolean.optional().nullable(),
89+
occupation: z.string().optional().nullable(),
90+
occupation_title: z.string().optional().nullable(),
91+
political_beliefs: z.array(z.string()).optional().nullable(),
92+
political_details: z.string().optional().nullable(),
93+
pref_romantic_styles: z.array(z.string()).nullable(),
94+
religion: z.array(z.string()).optional().nullable(),
95+
religious_belief_strength: z.number().optional().nullable(),
96+
religious_beliefs: z.string().optional().nullable(),
97+
twitter: z.string().optional().nullable(),
98+
university: z.string().optional().nullable(),
99+
website: z.string().optional().nullable(),
100100
})
101101

102102
export const combinedProfileSchema =

common/src/profiles/compatibility-util.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { ProfileRow } from 'common/profiles/profile'
22
import {MAX_INT, MIN_INT} from "common/constants";
33

44
const isPreferredGender = (
5-
preferredGenders: string[] | undefined,
6-
gender: string | undefined
5+
preferredGenders: string[] | undefined | null,
6+
gender: string | undefined | null,
77
) => {
88
// console.debug('isPreferredGender', preferredGenders, gender)
9-
if (preferredGenders === undefined || preferredGenders.length === 0 || gender === undefined) return true
9+
if (!preferredGenders?.length || !gender) return true
1010

1111
// If simple gender preference, don't include non-binary.
1212
if (
13-
preferredGenders.length === 1 &&
13+
preferredGenders?.length === 1 &&
1414
(preferredGenders[0] === 'male' || preferredGenders[0] === 'female')
1515
) {
1616
return preferredGenders.includes(gender)
@@ -43,30 +43,33 @@ export const areLocationCompatible = (profile1: ProfileRow, profile2: ProfileRow
4343
!profile2.city_latitude ||
4444
!profile1.city_longitude ||
4545
!profile2.city_longitude
46-
)
46+
) {
47+
if (!profile1.city || !profile2.city) return true
4748
return profile1.city.trim().toLowerCase() === profile2.city.trim().toLowerCase()
49+
}
4850

4951
const latitudeDiff = Math.abs(profile1.city_latitude - profile2.city_latitude)
50-
const longigudeDiff = Math.abs(profile1.city_longitude - profile2.city_longitude)
52+
const longitudeDiff = Math.abs(profile1.city_longitude - profile2.city_longitude)
5153

52-
const root = (latitudeDiff ** 2 + longigudeDiff ** 2) ** 0.5
54+
const root = (latitudeDiff ** 2 + longitudeDiff ** 2) ** 0.5
5355
return root < 2.5
5456
}
5557

5658
export const areRelationshipStyleCompatible = (
5759
profile1: ProfileRow,
5860
profile2: ProfileRow
5961
) => {
62+
if (!profile1.pref_relation_styles?.length || !profile2.pref_relation_styles) return true
6063
return profile1.pref_relation_styles.some((style) =>
61-
profile2.pref_relation_styles.includes(style)
64+
profile2.pref_relation_styles?.includes(style)
6265
)
6366
}
6467

6568
export const areWantKidsCompatible = (profile1: ProfileRow, profile2: ProfileRow) => {
6669
const { wants_kids_strength: kids1 } = profile1
6770
const { wants_kids_strength: kids2 } = profile2
6871

69-
if (kids1 === undefined || kids2 === undefined) return true
72+
if (kids1 == null || kids2 == null) return true
7073

7174
const diff = Math.abs(kids1 - kids2)
7275
return diff <= 2

common/src/supabase/schema.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export type Database = {
533533
bio_text: string | null
534534
bio_tsv: unknown
535535
born_in_location: string | null
536-
city: string
536+
city: string | null
537537
city_latitude: number | null
538538
city_longitude: number | null
539539
comments_enabled: boolean
@@ -545,7 +545,7 @@ export type Database = {
545545
drinks_per_month: number | null
546546
education_level: string | null
547547
ethnicity: string[] | null
548-
gender: string
548+
gender: string | null
549549
geodb_city_id: string | null
550550
has_kids: number | null
551551
height_in_inches: number | null
@@ -562,8 +562,8 @@ export type Database = {
562562
political_details: string | null
563563
pref_age_max: number | null
564564
pref_age_min: number | null
565-
pref_gender: string[]
566-
pref_relation_styles: string[]
565+
pref_gender: string[] | null
566+
pref_relation_styles: string[] | null
567567
pref_romantic_styles: string[] | null
568568
referred_by_username: string | null
569569
region_code: string | null
@@ -574,7 +574,7 @@ export type Database = {
574574
university: string | null
575575
user_id: string
576576
visibility: Database['public']['Enums']['lover_visibility']
577-
wants_kids_strength: number
577+
wants_kids_strength: number | null
578578
website: string | null
579579
}
580580
Insert: {
@@ -584,7 +584,7 @@ export type Database = {
584584
bio_text?: string | null
585585
bio_tsv?: unknown
586586
born_in_location?: string | null
587-
city: string
587+
city?: string | null
588588
city_latitude?: number | null
589589
city_longitude?: number | null
590590
comments_enabled?: boolean
@@ -596,7 +596,7 @@ export type Database = {
596596
drinks_per_month?: number | null
597597
education_level?: string | null
598598
ethnicity?: string[] | null
599-
gender: string
599+
gender?: string | null
600600
geodb_city_id?: string | null
601601
has_kids?: number | null
602602
height_in_inches?: number | null
@@ -613,8 +613,8 @@ export type Database = {
613613
political_details?: string | null
614614
pref_age_max?: number | null
615615
pref_age_min?: number | null
616-
pref_gender: string[]
617-
pref_relation_styles: string[]
616+
pref_gender?: string[] | null
617+
pref_relation_styles?: string[] | null
618618
pref_romantic_styles?: string[] | null
619619
referred_by_username?: string | null
620620
region_code?: string | null
@@ -625,7 +625,7 @@ export type Database = {
625625
university?: string | null
626626
user_id: string
627627
visibility?: Database['public']['Enums']['lover_visibility']
628-
wants_kids_strength?: number
628+
wants_kids_strength?: number | null
629629
website?: string | null
630630
}
631631
Update: {
@@ -635,7 +635,7 @@ export type Database = {
635635
bio_text?: string | null
636636
bio_tsv?: unknown
637637
born_in_location?: string | null
638-
city?: string
638+
city?: string | null
639639
city_latitude?: number | null
640640
city_longitude?: number | null
641641
comments_enabled?: boolean
@@ -647,7 +647,7 @@ export type Database = {
647647
drinks_per_month?: number | null
648648
education_level?: string | null
649649
ethnicity?: string[] | null
650-
gender?: string
650+
gender?: string | null
651651
geodb_city_id?: string | null
652652
has_kids?: number | null
653653
height_in_inches?: number | null
@@ -664,8 +664,8 @@ export type Database = {
664664
political_details?: string | null
665665
pref_age_max?: number | null
666666
pref_age_min?: number | null
667-
pref_gender?: string[]
668-
pref_relation_styles?: string[]
667+
pref_gender?: string[] | null
668+
pref_relation_styles?: string[] | null
669669
pref_romantic_styles?: string[] | null
670670
referred_by_username?: string | null
671671
region_code?: string | null
@@ -676,7 +676,7 @@ export type Database = {
676676
university?: string | null
677677
user_id?: string
678678
visibility?: Database['public']['Enums']['lover_visibility']
679-
wants_kids_strength?: number
679+
wants_kids_strength?: number | null
680680
website?: string | null
681681
}
682682
Relationships: [

web/components/optional-profile-form.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {Races} from './race'
1717
import {Carousel} from 'web/components/widgets/carousel'
1818
import {tryCatch} from 'common/util/try-catch'
1919
import {ProfileRow} from 'common/profiles/profile'
20-
import {removeNullOrUndefinedProps} from 'common/util/object'
20+
import {removeUndefinedProps} from 'common/util/object'
2121
import {isEqual, range} from 'lodash'
2222
import {PlatformSelect} from 'web/components/widgets/platform-select'
2323
import {PLATFORM_LABELS, type Site, SITE_ORDER} from 'common/socials'
@@ -32,7 +32,8 @@ import {
3232
DIET_CHOICES,
3333
EDUCATION_CHOICES,
3434
POLITICAL_CHOICES,
35-
RELATIONSHIP_CHOICES, RELIGION_CHOICES,
35+
RELATIONSHIP_CHOICES,
36+
RELIGION_CHOICES,
3637
ROMANTIC_CHOICES
3738
} from "web/components/filters/choices";
3839
import toast from "react-hot-toast";
@@ -70,10 +71,10 @@ export const OptionalProfileUserForm = (props: {
7071

7172
const handleSubmit = async () => {
7273
setIsSubmitting(true)
73-
const {bio: _, ...otherProfileProps} = profile
74-
console.debug('otherProfileProps', removeNullOrUndefinedProps(otherProfileProps))
74+
const {bio: _bio, bio_text: _bio_text, bio_tsv: _bio_tsv, bio_length: _bio_length, ...otherProfileProps} = profile
75+
console.debug('otherProfileProps', removeUndefinedProps(otherProfileProps))
7576
const {error} = await tryCatch(
76-
updateProfile(removeNullOrUndefinedProps(otherProfileProps) as any)
77+
updateProfile(removeUndefinedProps(otherProfileProps) as any)
7778
)
7879
if (error) {
7980
console.error(error)

web/components/profile/profile-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export default function ProfileHeader(props: {
5555
return (
5656
<Col className="w-full">
5757
<Row className={clsx('flex-wrap justify-between gap-2 py-1')}>
58-
{currentUser && isCurrentUser && disabled && <div className="text-red-500">You disabled your profile, so no one else can access it.</div>}
5958
<Row className="items-center gap-1">
6059
<Col className="gap-1">
60+
{currentUser && isCurrentUser && disabled && <div className="text-red-500">You disabled your profile, so no one else can access it.</div>}
6161
<Row className="items-center gap-1 text-xl">
6262
{!isCurrentUser && <OnlineIcon last_online_time={userActivity?.last_online_time}/>}
6363
<span>

0 commit comments

Comments
 (0)