Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Partial Updates to User Profile in updateProfile Function #166

Merged
merged 11 commits into from
Sep 10, 2024

Conversation

mayura-andrew
Copy link
Member

Purpose

The purpose of this PR is to fix #165

Goals

  • Ensure that the updateProfile function correctly handles partial updates to a user's profile.
  • Validate all required fields and ensure they are correctly typed.
    Handle errors gracefully and return appropriate error messages.

Approach

  • Validate input data using a schema validation library like zod.
  • Use the repository's update method to update the profile in the database.
  • Retrieve and return the updated profile along with a success message.

Screenshots

Checklist

  • This PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
  • I have read and understood the development best practices guidelines ( http://bit.ly/sef-best-practices )
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Related PRs

Test environment

Nodejs : V20.15
OS: Linux Mint 21.3

Learning

mayura-andrew and others added 10 commits July 14, 2024 20:28
Instead of directly passing individual fields to the updateProfile function, refactor the logic to use a single updateData object. This object contains the updated fields for the profile, such as primary_email, first_name, last_name, and image_url. This change improves code readability and maintainability.

Related to sef-global#165
Comment on lines 18 to 26

const updatedFields: Partial<Profile> = {}

if (updateData.primary_email)
updatedFields.primary_email = updateData.primary_email
if (updateData.first_name) updatedFields.first_name = updateData.first_name
if (updateData.last_name) updatedFields.last_name = updateData.last_name
if (updateData.image_url) updatedFields.image_url = updateData.image_url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const updatedFields: Partial<Profile> = {}
if (updateData.primary_email)
updatedFields.primary_email = updateData.primary_email
if (updateData.first_name) updatedFields.first_name = updateData.first_name
if (updateData.last_name) updatedFields.last_name = updateData.last_name
if (updateData.image_url) updatedFields.image_url = updateData.image_url
const { primary_email, first_name, last_name, image_url } = updateData;
const updatedFields: Partial<Profile> = { primary_email, first_name, last_name, image_url };

@anjula-sack anjula-sack merged commit 2712f07 into sef-global:main Sep 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Type Compatibility Issues in updateProfile Function
2 participants