This is the backend for Rentverse, a property rental application. It provides a RESTful API for managing users, properties, and authentication.
- User registration and authentication (login/logout) with role-based access control (
Admin,Owner,Tenant). - JWT-based authentication for secure endpoints.
- Full CRUD (Create, Read, Update, Delete) operations for properties.
- Image uploads for properties using
multerand cloud storage with Cloudinary. - Data validation for incoming requests using
class-validatorandclass-transformer. - Structured and consistent API responses.
- Centralized error handling middleware.
- Property availability check to prevent double-booking.
- Backend: Node.js, Express.js, TypeScript
- Database: MongoDB (managed with Prisma ORM)
- Authentication: JWT (JSON Web Tokens) with
jsonwebtoken - Image Storage: Cloudinary
- ORM: Prisma
- Validation:
class-validator,class-transformer - Password Hashing:
bcryptjs - Middleware:
cors,helmet,morgan - File Uploads:
multer
All endpoints are prefixed with /api.
Note: For all authenticated requests, you must include an Authorization header with the value Bearer <your_jwt_token>.
-
POST /auth/register- Description: Register a new user.
- Role: Public
- Body:
Note:
{ "name": "John Doe", "email": "john.doe@example.com", "password": "password123", "role": "Tenant" }rolecan beTenantorOwner.
-
POST /auth/login- Description: Login a user to get a JWT token.
- Role: Public
- Body:
{ "email": "john.doe@example.com", "password": "password123" }
-
GET /profile- Description: Get the profile of the currently logged-in user.
- Role:
Admin,Owner,Tenant
-
PUT /profile- Description: Update the profile of the currently logged-in user.
- Role:
Admin,Owner,Tenant
-
GET /api/properties- Description: Get all approved properties. Can be filtered by a
searchquery parameter. - Role: Public
- Description: Get all approved properties. Can be filtered by a
-
GET /api/properties/:id- Description: Get a specific approved property by its ID.
- Role: Public
-
GET /api/tenant/properties- Description: Get all available properties (status:
Approved). Can be filtered bypropertyTypequery parameter. - Role:
Tenant
- Description: Get all available properties (status:
-
GET /api/tenant/properties/:id- Description: Get a specific available property by its ID.
- Role:
Tenant
-
POST /api/tenant/rent/:propertyId- Description: Create a new rent for a property. Checks availability to prevent overlapping rentals.
- Role:
Tenant - Body (JSON):
{ "startDate": "2025-10-01T00:00:00.000Z", "duration": 6, "eSignature": "optional string", "eMaterai": "optional string" }Notes:
durationis treated as months (end date = start date + duration months).rentalAmountis calculated asproperty.price * duration.
-
GET /api/tenant/rent/history- Description: Get the rent history for the logged-in tenant.
- Role:
Tenant
-
POST /api/owner/property- Description: Create a new property listing.
- Role:
Owner - Upload (multipart/form-data):
images(up to 5 files, JPG/PNG/JPEG)ownershipCertificate(1 PDF). The certificate is encrypted server-side and stored in Cloudinary.
-
GET /api/owner/properties- Description: Get all properties owned by the logged-in user.
- Role:
Owner
-
GET /api/owner/property/:id- Description: Get a specific property by its ID, owned by the logged-in user.
- Role:
Owner
-
PUT /api/owner/property/:id- Description: Update an existing property owned by the logged-in user.
- Role:
Owner
-
DELETE /api/owner/property/:id- Description: Delete a property owned by the logged-in user.
- Role:
Owner
-
GET /api/owner/property/:id/certificate- Description: Downloads and decrypts the ownership certificate for a specific property.
- Role:
Owner
-
GET /api/admin/users- Description: Get all users. Can be filtered by
rolequery parameter. - Role:
Admin
- Description: Get all users. Can be filtered by
-
GET /api/admin/users/:id- Description: Get a specific user by their ID.
- Role:
Admin
-
GET /api/admin/property- Description: Get all properties from all users.
- Role:
Admin
-
GET /api/admin/property/owner/:ownerId- Description: Get all properties for a specific owner.
- Role:
Admin
-
GET /api/admin/property/:id- Description: Get a specific property by its ID.
- Role:
Admin
-
PUT /api/admin/property/:id- Description: Update the status of a property (e.g.,
Pending,Approved,Rejected). - Role:
Admin
- Description: Update the status of a property (e.g.,
Create a .env file with the following variables:
DATABASE_URL="mongodb+srv://<user>:<pass>@<cluster>/<db>?retryWrites=true&w=majority"
# JWT
# JWT_SECRET="your_jwt_secret" # If your auth module uses it
# Cloudinary
CLOUDINARY_CLOUD_NAME="your_cloud_name"
CLOUDINARY_API_KEY="your_api_key"
CLOUDINARY_API_SECRET="your_api_secret"
# File encryption (must be exactly 32 characters)
FILE_ENCRYPTION_KEY="32-characters-long-secret-key!!!"
# Price prediction service (Owner feature)
PREDICT_API_URL="https://your-flask-service/predict"
Notes:
FILE_ENCRYPTION_KEYmust be exactly 32 characters (AES-256-CBC).- Ownership certificate files are encrypted and stored as raw files in Cloudinary.
- Tenant rent
durationis treated as months in the current implementation.