A digital wallet management system built with Node.js, Express, TypeScript, and MongoDB. Users can register, manage wallets, send/receive money, and agents/admins have specialized operations. The system supports authentication, role-based access, and transaction history.
-
Clone the repository
git clone <repo-url> cd assignment-05
-
Install dependencies
npm install
-
Configure environment variables
Create a
.envfile in the root directory with the following variables:PORT=5000 MONGO_URI=<your-mongodb-uri> JWT_SECRET=<your-jwt-secret> JWT_EXPIRES_IN=3d CASH_IN_COMMISSION=0.02 CASH_OUT_COMMISSION=0.02 BCRYPT_SALT_ROUNDS=10 -
Run the app in development
npm run dev
-
Build for production
npm run build npm start
- User registration and login
- JWT-based authentication
- Role-based authorization (user, agent, admin)
- Wallet management (top-up, withdraw, send money)
- Agent operations (cash-in, cash-out, commission tracking)
- Admin operations (block/unblock users, suspend/activate agents, view all users/wallets/transactions)
- Input validation using Zod
- MongoDB integration via Mongoose
- Backend: Node.js, Express
- Language: TypeScript
- Database: MongoDB (Mongoose ODM)
- Authentication: JWT
- Validation: Zod
- Other: bcrypt, dotenv, cookie-parser, cors
-
POST /api/v1/auth/register
Register a new user.
Body:{ name, phone, password } -
POST /api/v1/auth/login
Login with phone and password.
Body:{ phone, password }
-
POST /api/v1/wallet/top-up
Add money to wallet.
Body:{ amount } -
POST /api/v1/wallet/withdraw
Withdraw money from wallet.
Body:{ amount } -
POST /api/v1/wallet/send-money
Send money to another user.
Body:{ receiverPhone, amount } -
GET /api/v1/wallet/transactions
Get transaction history. -
GET /api/v1/wallet/balance
Get current wallet balance.
-
POST /api/v1/agent/cash-in
Agent cash-in for user.
Body:{ userPhone, amount } -
POST /api/v1/agent/cash-out
Agent cash-out for user.
Body:{ userPhone, amount } -
GET /api/v1/agent/commissions
Get agent commission history.
-
GET /api/v1/admin/users
Get all users. -
GET /api/v1/admin/agents
Get all agents. -
GET /api/v1/admin/wallets
Get all wallets. -
GET /api/v1/admin/transactions
Get all transactions. -
PATCH /api/v1/admin/user/block
Block a user.
Body:{ userId } -
PATCH /api/v1/admin/user/unblock
Unblock a user.
Body:{ userId } -
PATCH /api/v1/admin/agent/suspend
Suspend an agent.
Body:{ userId } -
PATCH /api/v1/admin/agent/activate
Activate an agent.
Body:{ userId }
Note: All wallet, agent, and admin endpoints require authentication and