A NodeJS application for managing user transactions with MongoDB.
- Get user details by ID
- Get user transactions with filters
- Get all transactions with user details and filters
- Pagination support
- MongoDB aggregation framework implementation
- Input validation
- Error handling
- Node.js (v14 or higher)
- MongoDB Atlas account
- npm or yarn
- Clone the repository:
git clone [repository-url]
cd [project-directory]
- Install dependencies:
npm install
- Create
.env
file in the root directory:
MONGODB_URI=your_mongodb_connection_string
PORT=3000
- Seed the database:
node src/utils/seedData.js
- Test Endpoints Test each endpoint with different query parameters:
a) Get User:
GET {{baseUrl}}/api/users/:id
b) Get User Transactions:
GET {{baseUrl}}/api/users/:id/transactions?status=success&type=credit
c) Get All Transactions:
GET {{baseUrl}}/api/transactions?fromDate=2024-01-01&toDate=2024-01-31
GET /api/users/:id
Parameters:
id
: MongoDB ObjectId of the user
GET /api/users/:id/transactions
Parameters:
id
: MongoDB ObjectId of the user Query Parameters:status
: (optional) success/pending/failedtype
: (optional) debit/creditfromDate
: (optional) ISO date stringtoDate
: (optional) ISO date stringpage
: (optional) page number (default: 1)limit
: (optional) items per page (default: 10)
GET /api/transactions
Query Parameters:
status
: (optional) success/pending/failedtype
: (optional) debit/creditfromDate
: (optional) ISO date stringtoDate
: (optional) ISO date stringpage
: (optional) page number (default: 1)limit
: (optional) items per page (default: 10)
The API implements comprehensive error handling for:
- Invalid ObjectId format
- Invalid date formats
- Invalid status or type values
- Missing required parameters
- Database connection errors
Run the application in development mode:
npm run dev
Import the Postman collection from the postman
directory to test the APIs.
The application is deployed on [Render] and can be accessed at [(https://backend-api-7b6x.onrender.com/)].