WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Variable UserProfileUpdateSchemaConst

    UserProfileUpdateSchema: ZodObject<
        {
            username: ZodOptional<ZodString>;
            country_code: ZodOptional<ZodString>;
            profile_picture_url: ZodOptional<ZodString>;
        },
        "strip",
        ZodTypeAny,
        { username?: string; country_code?: string; profile_picture_url?: string },
        { username?: string; country_code?: string; profile_picture_url?: string },
    > = ...

    User profile update validation schema for self-service profile management

    Comprehensive validation schema for user profile update operations that allows users to modify their personal information including username, country location, and profile picture. This schema supports progressive profile completion by making all fields optional, enabling users to update their profiles incrementally while maintaining data quality through comprehensive field validation.

    The profile update schema ensures data integrity through reusable validation components, supports internationalization through country code validation, maintains platform quality through username format enforcement, and enables personalization through profile picture URL validation. All fields are optional to support flexible user experience patterns and progressive disclosure.

    User experience considerations include optional field updates that don't require complete profile information, validation feedback that guides users toward successful profile completion, flexible update patterns that support various user interface designs, and privacy-conscious validation that respects user choice in profile information sharing.

    Security features include input sanitization for all profile fields, URL validation to prevent malicious link injection, username format validation to prevent injection attacks, and country code validation to ensure data consistency and prevent geographic data manipulation.

    // Complete profile update
    const profileUpdate = {
    username: 'language_learner_2024',
    country_code: 'PE',
    profile_picture_url: 'https://example.com/avatars/user123.jpg'
    };

    const result = UserProfileUpdateSchema.parse(profileUpdate);
    console.log('Valid profile update:', result);
    // Partial profile update (username only)
    const usernameUpdate = {
    username: 'new_username'
    };

    const result = UserProfileUpdateSchema.parse(usernameUpdate);
    // Other fields remain unchanged
    // Profile update endpoint with validation
    router.put('/profile',
    authenticateToken,
    validate({ body: UserProfileUpdateSchema }),
    async (req, res) => {
    const updates = req.body; // Validated profile updates
    const userId = req.user.id;

    const updatedProfile = await userService.updateProfile(userId, updates);

    res.json({
    success: true,
    profile: updatedProfile,
    message: 'Profile updated successfully'
    });
    }
    );
    // Progressive profile completion
    const profileSteps = [
    { username: 'student123' }, // Step 1: Choose username
    { country_code: 'MX' }, // Step 2: Set location
    { profile_picture_url: 'https://...' } // Step 3: Add avatar
    ];

    for (const step of profileSteps) {
    const validation = UserProfileUpdateSchema.safeParse(step);
    if (validation.success) {
    await userService.updateProfile(userId, validation.data);
    }
    }
    // Mobile app profile management
    const mobileProfileUpdate = async (updates: Partial<UserProfileUpdateRequest>) => {
    const validation = UserProfileUpdateSchema.safeParse(updates);

    if (!validation.success) {
    throw new ValidationError('Invalid profile data', validation.error.errors);
    }

    return await fetch('/api/profile', {
    method: 'PUT',
    headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${accessToken}`
    },
    body: JSON.stringify(validation.data)
    });
    };
    // Profile validation with user feedback
    const validateProfileUpdate = (formData: any) => {
    const result = UserProfileUpdateSchema.safeParse(formData);

    if (!result.success) {
    const fieldErrors = result.error.errors.reduce((acc, err) => {
    const field = err.path[0] as string;
    acc[field] = err.message;
    return acc;
    }, {} as Record<string, string>);

    return { isValid: false, errors: fieldErrors };
    }

    return { isValid: true, data: result.data };
    };