fix major check and update not success

pull/21891/head
ytqh 1 year ago
parent 1d4a1ae89d
commit 806e2a6bb1

@ -105,8 +105,12 @@ class UserProfile(Resource):
# Validate major if provided
if 'major' in data:
major = data['major']
if len(major) > 20:
if isinstance(major, str) and len(major) > 20:
return {"success": False, "message": "Major exceeds maximum length"}, 400
elif major is not None: # Handle non-string or None values appropriately
return {"success": False, "message": "Major must be a string value"}, 400
validated_data['major'] = major
# Use the service to update user profile

@ -70,12 +70,17 @@ class EndUserService:
if 'major' in profile_data:
major = profile_data['major']
# Initialize extra_profile if it doesn't exist
if not end_user.extra_profile:
# Create a new dictionary if extra_profile is None
if end_user.extra_profile is None:
end_user.extra_profile = {}
# Update major in extra_profile
end_user.extra_profile['major'] = major
# Make a copy of the existing dictionary to ensure changes are detected
extra_profile = dict(end_user.extra_profile)
extra_profile['major'] = major
end_user.extra_profile = extra_profile
# Force the change to be detected
db.session.add(end_user)
# Save changes to database
db.session.commit()

Loading…
Cancel
Save