feat(api): build portfolio, transaction & agent APIs with WhatsApp formatter layer (#6)#12
Merged
robertocarlous merged 2 commits intoNeurowealth:mainfrom Mar 8, 2026
Conversation
Contributor
|
Can you attach a screenshot of your tests passing |
Contributor
Author
|
okay |
Contributor
Author
Contributor
Author
|
@robertocarlous can you review and merge this? |
Contributor
|
Hello @Chucks1093 Pls pull main branch and sync with your branch and run ci to ensure it pass, so i can merge,thank you |
Contributor
Author
|
Okay |
…APIs with whatsapp formatters (Neurowealth#6)
48b30f0 to
bc47312
Compare
Contributor
Author
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.

Closes #6
Summary
Implemented the WhatsApp-first API surface for portfolio, transactions, protocols/agent status, deposit, and withdraw flows, including a formatter layer that converts structured data into chat-optimized replies.
Changes
API Routes Added
GET /api/portfolio/:userIdGET /api/portfolio/:userId/history?period=7d|30d|90dGET /api/portfolio/:userId/earningsGET /api/transactions/:userId?page=1&limit=5GET /api/transactions/detail/:txHashGET /api/protocols/ratesGET /api/protocols/agent/statusPOST /api/depositPOST /api/withdrawRoute Registration
src/index.ts:/api/portfolio/api/transactions/api/protocols/api/deposit/api/withdrawAuthentication + Access Control
src/middleware/auth.ts:requireAuthfor bearer token/session authenticationenforceUserAccessto ensure user-specific endpoints can only access own dataValidation + Status Codes
zodinput validation for query/body payloads.401Unauthorized (missing/invalid token, wrong user access)404Not Found (missing user/tx/agent status)409Conflict (duplicate deposittxHash)400Validation errorWhatsApp Formatter Layer (Critical)
src/whatsapp/formatters.tswith formatter functions for all user-facing responses:*bold*,_italic_, concise mobile-readable lines, emojis).Deposit & Withdraw Requirements
POST /api/depositreturnswhatsappReply.POST /api/withdrawreturnswhatsappReply.txHashreturns409.Testing
tests/integration/api/api.test.tstests/setupEnv.tstsconfig.test.json.Test Coverage Added (Integration)
401without token404for missing userlimit = 5409whatsappReplyBuild / Verification
npm run lint✅npm run test✅npm run build✅ (zero TypeScript errors)Notes
whatsappReplystrings for chat delivery through Twilio.app.listen()only runs when executed directly, which improves testability.