An open API service indexing awesome lists of open source software.

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.

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`