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

BE - Allow User to Make Their Profile Public or Private #63

Open
5 tasks
sanjaysah101 opened this issue Sep 19, 2024 · 0 comments
Open
5 tasks

BE - Allow User to Make Their Profile Public or Private #63

sanjaysah101 opened this issue Sep 19, 2024 · 0 comments

Comments

@sanjaysah101
Copy link
Collaborator

Description:

We need to implement functionality that allows users to toggle their profile visibility between public and private. By default, profiles are public, but users should have the option to make their profile private if they choose.


Key Requirements:

  1. Toggle Profile Visibility API:

    • Implement the PATCH /profile/visibility route to allow users to update the visibility of their profile (public or private).
    • Example:
      router.patch('/profile/visibility', validateAccessToken, ProfileController.toggleProfileVisibility);
    • Use the validateAccessToken middleware to authenticate the requesting user.
  2. Profile Schema Update:

    • Add isPublic in the profile schema to store the visibility status of the user's profile.
    • The default value should be true (public).
    • Example schema:
      isPublic: { type: Boolean, default: true },
  3. Profile Visibility Logic:

    • Public Profiles (isPublic: true): When a profile is public, anyone can view the restricted fields as mentioned in the "View Another User's Profile" issue.
    • Private Profiles (isPublic: false): If a profile is private, it will not be viewable by others except for a message like: "This profile is private."
  4. Profile Controller and Service:

    • Implement a toggleProfileVisibility method in ProfileController to handle toggling the profile's isPublic status.
    • Add logic in ProfileService to update the profile's visibility based on the authenticated user making the request.
  5. Zod Validation:

    • Use Zod to validate the request payload, ensuring only the isPublic field is allowed to be updated in this API call.
    • Example:
      export const toggleVisibilitySchema = z.object({
        isPublic: z.boolean(),
      });
  6. Test Cases:
    Write unit tests for the following scenarios:

    • Success: Test that authenticated users can successfully toggle the visibility of their profile.
    • Invalid Data: Ensure invalid data (e.g., non-boolean values for isPublic) are rejected by the validation schema.
    • Authentication: Verify that only authenticated users can update their profile visibility.

Tasks:

  • Implement the toggleProfileVisibility method in ProfileController to update the isPublic flag.
  • Add the PATCH /profile/visibility route in profile.route.ts.
  • Use Zod for validation of the isPublic field in profile.validation.ts.
  • Ensure validateAccessToken middleware is used to authenticate the user.
  • Write test cases for:
    • Success: Ensure users can toggle the visibility of their profile.
    • Invalid Data: Reject invalid values for isPublic.
    • Authentication Enforcement: Ensure only authenticated users can update their profile visibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant