https://github.com/wahedpro/level2-assignment-02
A complete backend system for managing vehicle rentals, bookings, customers, and admin operations. Built with Node.js, TypeScript, Express, PostgreSQL, and fully secured using JWT authentication.
https://github.com/wahedpro/level2-assignment-02
express jwt node postgresql typescript
Last synced: 3 months ago
JSON representation
A complete backend system for managing vehicle rentals, bookings, customers, and admin operations. Built with Node.js, TypeScript, Express, PostgreSQL, and fully secured using JWT authentication.
- Host: GitHub
- URL: https://github.com/wahedpro/level2-assignment-02
- Owner: wahedpro
- Created: 2025-12-04T14:28:22.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-12-07T15:26:17.000Z (7 months ago)
- Last Synced: 2025-12-08T14:25:55.988Z (7 months ago)
- Topics: express, jwt, node, postgresql, typescript
- Language: TypeScript
- Homepage: https://vehicle-rental-system-rho.vercel.app
- Size: 77.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Vehicle Rental System โ Backend API
A complete backend system for managing vehicle rentals, bookings, customers, and admin operations.
Built with **Node.js, TypeScript, Express, PostgreSQL**, and fully secured using **JWT authentication**.
---
## ๐ Live API URL
๐ https://vehicle-rental-system-rho.vercel.app
---
# โญ Project Features
## ๐ Authentication & Authorization
- User Registration & Login (JWT-based)
- Role-based Access Control:
- **Admin** โ full system access
- **Customer** โ limited access (own profile, own bookings)
---
## ๐ Vehicle Management (Admin Only)
- Create Vehicle
- Get All Vehicles
- Get Vehicle by ID
- Update Vehicle
- Delete Vehicle
- Automatic availability updates based on booking status
---
## ๐ค User Management
- Admin โ Get all users
- Admin โ Update any user
- User โ Update own profile
- Admin โ Delete user (only if no active bookings)
---
## ๐
Booking Management
- Customer/Admin โ Create booking
- Auto price calculation:
```
total_price = daily_rent_price ร number_of_days
```
- Customer โ Cancel own booking
- Admin โ Mark booking as returned
- Vehicle availability auto-update
- Role-based booking retrieval:
- Admin โ all bookings
- Customer โ only own bookings
---
## ๐ Auto Return System (Cron Job)
A scheduled background job that:
- Automatically checks for expired bookings
- Marks them as `"returned"`
- Sets the vehicle status back to `"available"`
Runs every **1 minute** using `node-cron`.
---
# ๐ ๏ธ Technology Stack
| Category | Technology |
|----------|------------|
| Language | TypeScript |
| Runtime | Node.js |
| Framework | Express.js |
| Database | PostgreSQL |
| Auth | JWT + bcrypt |
| Scheduler | node-cron |
| Hosting | Vercel |
---
# ๐ Project Structure
```
src/
โโ app.ts
โโ server.ts
โโ database/
โ โโ db.ts
โโ middlewares/
โ โโ auth.middleware.ts
โโ modules/
โ โโ auth/
โ โโ users/
โ โโ vehicles/
โ โโ bookings/
โ โโ autoReturn/
โโ utils/
โโ response.ts
```
---
# โ๏ธ Setup & Installation Guide
## 1๏ธโฃ Clone the repository
```
git clone https://github.com/wahedpro/Level2-Assignment-02.git
cd vehicle-rental-system
```
## 2๏ธโฃ Install dependencies
```
npm install
```
## 3๏ธโฃ Configure Environment Variables
Create a `.env` file:
```
PORT=5000
DATABASE_URL=your_postgres_url
JWT_SECRET=your_secret_key
```
## 4๏ธโฃ Run the project (development)
```
npm run dev
```
## 5๏ธโฃ Build & run production build
```
npm run build
npm start
```
---
# ๐งช API Endpoints Overview
## ๐ Auth
- `POST /api/v1/auth/signup`
- `POST /api/v1/auth/signin`
## ๐ Vehicles
- `POST /api/v1/vehicles`
- `GET /api/v1/vehicles`
- `GET /api/v1/vehicles/:id`
- `PUT /api/v1/vehicles/:id`
- `DELETE /api/v1/vehicles/:id`
## ๐ค Users
- `GET /api/v1/users`
- `PUT /api/v1/users/:id`
- `DELETE /api/v1/users/:id`
## ๐
Bookings
- `POST /api/v1/bookings`
- `GET /api/v1/bookings`
- `PUT /api/v1/bookings/:id`