@@ -620,6 +620,7 @@ async def update_or_create_profile(
620620 """
621621 Update the store profile for a user. Creates a new profile if one doesn't exist.
622622 Only allows updating if the user_id matches the owning user.
623+ If a field is None, it will not overwrite the existing value in the case of an update.
623624
624625 Args:
625626 user_id: ID of the authenticated user
@@ -630,8 +631,9 @@ async def update_or_create_profile(
630631
631632 Raises:
632633 HTTPException: If user is not authorized to update this profile
634+ DatabaseError: If profile cannot be updated due to database issues
633635 """
634- logger .debug (f"Updating profile for user { user_id } " )
636+ logger .info (f"Updating profile for user { user_id } data: { profile } " )
635637
636638 try :
637639 # Check if profile exists for user
@@ -641,16 +643,19 @@ async def update_or_create_profile(
641643
642644 # If no profile exists, create a new one
643645 if not existing_profile :
644- logger .debug (f"Creating new profile for user { user_id } " )
646+ logger .debug (
647+ f"No existing profile found. Creating new profile for user { user_id } "
648+ )
645649 # Create new profile since one doesn't exist
646650 new_profile = await prisma .models .Profile .prisma ().create (
647651 data = {
648652 "userId" : user_id ,
649653 "name" : profile .name ,
650654 "username" : profile .username ,
651655 "description" : profile .description ,
652- "links" : profile .links ,
656+ "links" : profile .links or [] ,
653657 "avatarUrl" : profile .avatar_url ,
658+ "isFeatured" : False ,
654659 }
655660 )
656661
@@ -666,16 +671,23 @@ async def update_or_create_profile(
666671 )
667672 else :
668673 logger .debug (f"Updating existing profile for user { user_id } " )
674+ # Update only provided fields for the existing profile
675+ update_data = {}
676+ if profile .name is not None :
677+ update_data ["name" ] = profile .name
678+ if profile .username is not None :
679+ update_data ["username" ] = profile .username
680+ if profile .description is not None :
681+ update_data ["description" ] = profile .description
682+ if profile .links is not None :
683+ update_data ["links" ] = profile .links
684+ if profile .avatar_url is not None :
685+ update_data ["avatarUrl" ] = profile .avatar_url
686+
669687 # Update the existing profile
670688 updated_profile = await prisma .models .Profile .prisma ().update (
671689 where = {"id" : existing_profile .id },
672- data = prisma .types .ProfileUpdateInput (
673- name = profile .name ,
674- username = profile .username ,
675- description = profile .description ,
676- links = profile .links ,
677- avatarUrl = profile .avatar_url ,
678- ),
690+ data = prisma .types .ProfileUpdateInput (** update_data ),
679691 )
680692 if updated_profile is None :
681693 logger .error (f"Failed to update profile for user { user_id } " )
0 commit comments