Skip to content

feat: replace mock user helpers with Prisma-backed profile API#107

Open
Yilkash wants to merge 1 commit into
learnault:mainfrom
Yilkash:replace-mock-users-85
Open

feat: replace mock user helpers with Prisma-backed profile API#107
Yilkash wants to merge 1 commit into
learnault:mainfrom
Yilkash:replace-mock-users-85

Conversation

@Yilkash

@Yilkash Yilkash commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Replaces hard-coded mock user helpers in UserController with real Prisma queries. Adds profile fields to the User model, a LearnerProfile model for public/private profile data with consent controls, and an OnboardingState model for tracking user onboarding progress.

Changes

Prisma Schema

  • User: Added firstName, lastName, bio, avatar columns
  • LearnerProfile (new): displayName, country, timezone, languages, skillLevel, interests, goals, visibility (public/private/mentor_only), consentGiven
  • OnboardingState (new): profileComplete, emailVerified, walletConnected, firstSessionBooked, firstCredentialEarned, consentProvided, completedSteps, currentStep, dismissed

Services

  • user.service.ts: New service with Prisma-backed methods replacing all mock helpers:
    • findUserById — fetches user with profile, onboarding, and profile completion
    • updateUserProfile — Prisma update with computed completion
    • updateUserProfileData — upserts LearnerProfile
    • validatePassword — uses bcrypt.compare
    • updateUserPassword — uses bcrypt.hash
    • updateUserWallet — updates wallet + marks onboarding step
    • getPublicProfile — consent-aware visibility check
    • getProfileCompletion, getOnboardingState

Controller

  • Removed all 6 mock helper methods (findUserById, updateUserProfile, updateUserWallet, validatePassword, updateUserPassword)
  • All endpoints now call user.service methods
  • Audit logging added for PROFILE_UPDATED, PASSWORD_CHANGED, WALLET_UPDATED
  • getUserById returns consent-aware public profile (respects LearnerProfile.visibility)
  • Responses include profileCompletion and onboarding state

Routes

  • Added GET /me/profile for extended profile read

Tests

  • Rewrote user.controller.test.ts to mock Prisma directly (following auth.controller.test.ts pattern)
  • 13 tests covering auth, not found, conflict, privacy, wallet validation, and profile update

Verification

  • npx tsc --noEmit — 0 errors
  • pnpm test — 318 tests pass across 20 test files

Closes: #85

- Add firstName, lastName, bio, avatar fields to User model in Prisma schema
- Add LearnerProfile model with display name, country, timezone, languages,
  skill level, interests, goals, and visibility/consent controls
- Add OnboardingState model tracking profile completion, email verification,
  wallet connection, session booking, credential earning, and consent
- Create user.service.ts with Prisma-backed methods:
  - findUserById with profile, onboarding, and profile completion
  - updateUserProfile with audit logging
  - updateUserProfileData for LearnerProfile upsert
  - validatePassword using bcrypt.compare
  - updateUserPassword using bcrypt hash
  - updateUserWallet with onboarding state update
  - getPublicProfile with consent-aware visibility check
  - getProfileCompletion and getOnboardingState
- Update UserController to use service instead of mock helpers
- Add audit logging for PROFILE_UPDATED, PASSWORD_CHANGED, WALLET_UPDATED
- Add public profile read respecting LearnerProfile visibility
- Return profileCompletion and onboardingState in user responses
- Add GET /me/profile route for extended profile
- Update tests to mock Prisma instead of spying on private methods
- All 318 tests pass, TypeScript compiles cleanly

Closes: learnault#85
@Yilkash
Yilkash force-pushed the replace-mock-users-85 branch from 557fd40 to 60df40e Compare July 20, 2026 07:07

@3m1n3nc3 3m1n3nc3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please sync your fork and resolve conflicts.

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.

Feature: Replace Mock User Helpers with Profile API

3 participants