fix(users): replace mock profile helpers with Prisma persistence - #20
Merged
merlik787-droi merged 1 commit intoAug 19, 2026
Conversation
Replace the fabricated findUserById/updateUserProfile/validatePassword/ updateUserWallet helpers with real Prisma lookups, bcrypt password verification and hashing, and wallet updates that map unique-constraint conflicts to 409. Align the User type, validation middleware, OpenAPI schemas, and docs with the actual persisted columns (dropping the unstorable firstName/lastName/bio/avatar/status/isActive fields).
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #10
The four
/users/*endpoints were built on private helpers that returned fabricated fixtures (findUserByIdreturnedtest@example.com,validatePasswordreturnedfalse,updateUserPasswordthrewNot implemented). This PR replaces them with real Prisma lookups/updates and bcrypt password handling, and removes the profile fields the database cannot store (firstName/lastName/bio/avatar/status/isActive) from theUsertype, validation middleware, OpenAPI schemas, and docs.Why
The controller had no persistence layer and the
Userinterface disagreed withprisma/schema.prisma(which only hasemail,username,password,role,walletAddress, timestamps). Rather than add columns for fields nothing consumes, this PR removes the unstorable fields so the type, schema, validation, and docs all describe the same contract, and implements every endpoint honestly against Prisma. Password changes reuse the existingbcrypt.compare/bcrypt.hashpattern fromauth.controller.ts; a wallet@uniqueconflict maps to 409 instead of the previous catch-all 500.What was built
src/controllers/user.controller.tsfindUserById/updateUserProfile/validatePassword/updateUserPassword/updateUserWallethelpers over Prisma;updateUserWallettranslates a P2002 unique violation to a 409. Responses expose only persisted fields and never the password hash.src/types/user.types.tsUser/PublicUserInfo/UpdateUserDataaligned to the actual columns; removedUserStatus,CreateUserData,UpdateWalletData,UpdateUserRoleData,UpdateUserStatusData,UserFilterParams(all unused).src/middleware/validation.middleware.tsvalidateProfileUpdatenow only acceptsusername(the sole mutable profile column).src/docs/schemas.tsUserandUpdateUserOpenAPI schemas dropfirstName/lastName/bio/avatar/isActive.docs/API.mdGET /users/me,PATCH /users/me, plus newPATCH /users/passwordandPATCH /users/walletexamples reflect the persisted shape.tests/user.controller.test.ts(+integrations/mirror)tests/unit/validation.middleware.test.ts(+integrations/mirror)Integration changes outside
src/controllers/user.controller.tssrc/types/user.types.ts—User/PublicUserInfo/UpdateUserDatareshaped; unused types removed.src/middleware/validation.middleware.ts— profile-update schema narrowed tousername.src/docs/schemas.ts— OpenAPIUser/UpdateUserschemas corrected.docs/API.md— user endpoint examples corrected.Acceptance criteria coverage
Profile
GET /users/mereturns the authenticated user's actual persisted row, not thetest@example.comfixture. (findUserById→prisma.user.findUnique;tests/user.controller.test.ts)PATCH /users/mepersists the validated fields viaprisma.user.updateand returns the updated row. (updateUserProfile;tests/user.controller.test.ts)Password
PATCH /users/passwordverifies the current password with bcrypt and persists the new hash. (validatePassword→bcrypt.compare,updateUserPassword→bcrypt.hash+prisma.user.update)tests/user.controller.test.ts)Wallet
PATCH /users/walletpersists the wallet address and returns it; a duplicate address returns an appropriate 4xx rather than 500. (updateUserWalletmapsP2002to 409;tests/user.controller.test.ts)Contract
Usertype, Prisma schema, validation middleware, anddocs/schemas.tsagree on the user fields. (unsupported fields removed consistently)Tests
tests/user.controller.test.tsrewritten)Documentation
docs/API.mdand the Swagger annotations reflect the actual persisted user fields. (docs/API.md+src/docs/schemas.ts)Test plan
pnpm test:ci— 274/274 passingpnpm exec tsc --noEmit— no type errorspnpm lint— no errors or warningspnpm build— succeedsnpx prisma generate— client regenerated (no schema change; ran to confirm)Env vars / Notes
No new environment variables or config keys, and no migration: the change removes unsupported fields rather than adding columns.
User.roleis typed asstringto avoid coupling this PR to the role-model defect (#4, which owns theRoleenum reconciliation); the role value is passed through unchanged from the persisted row. JWT invalidation on password change is left unchanged (the existing stateless-JWT design does not blacklist tokens).