A Node-Express application to manage a car store and process customer orders. The application supports features such as adding and updating car details, managing orders, and calculating revenue using MongoDB aggregation pipelines.
- Add new cars with details such as brand, model, year, price, and quantity.
- Update car details including price, quantity, and availability status.
- Automatically update car availability (inStock) based on inventory quantity.
- Place orders for cars with validation of inventory stock.
- Calculate the total price for orders dynamically.
- Handle scenarios like insufficient stock with user-friendly error messages.
- Compute total revenue from orders using MongoDB aggregation pipelines.
- Ensure accurate revenue tracking by validating stock availability during order placement.
Follow the instructions below to set up the project locally.
- Node.js (v16 or higher)
- MongoDB (Local or Atlas)
- A package manager (npm or yarn)
Clone the repository:
git clone https://github.com/RittikaDev/car-store-B4A2V3.git
cd car-store-B4A2V3Install dependencies:
npm installSet up environment variables:
- Create a .env file in the project root and configure secret keys
PORT=5000
DATABASE_URL=mongodb+srv://rittikadev:[email protected]/assignment-two?retryWrites=true&w=majority&appName=Cluster0Run the application:
npm run start:devBuild the application:
npm run buildAPI Documentation
- Once the server is running, you can access the API documentation (if Swagger or Postman is configured) or use the endpoints directly via Postman.
- Create a Car:
- POST /api/cars
- Request Body: { "brand": "BMW", "model": "X5", "year": 2023, "price": 50000, "quantity": 10, "category": "SUV", "description": "Luxury SUV" }
- Get All Cars:
- GET /api/cars?searchTerm=
- Get Single Car
- GET /api/cars/:carId
- Update a Car:
- PUT /api/cars/:carId
- Request Body: { "price": 55000, "quantity": 5 }
- Delete a Car
- DELETE /api/cars/:carId
- Create an Order:
- POST /api/orders
- Request Body: { "email": "[email protected]", "car": "", "quantity": 1, "totalPrice": 50000 }
- Get Total Revenue
- GET /api/orders/revenue
car-store-B4A2V3/
├── src/
│ ├── app/
│ │ ├── modules/
│ │ │ ├── car/
│ │ │ │ ├── car.controller.ts
│ │ │ │ ├── car.model.ts
│ │ │ │ ├── car.route.ts
│ │ │ │ ├── car.service.ts
│ │ │ │ ├── car.interface.ts
│ │ │ │ └── car.validation.ts
│ │ │ │
│ │ │ ├── order/
│ │ │ │ ├── order.controllers.ts
│ │ │ │ ├── order.model.ts
│ │ │ │ ├── order.route.ts
│ │ │ │ ├── order.service.ts
│ │ │ │ ├── order.interface.ts
│ │ │ │ └── order.validation.ts
│ │ ├─── config/
│ │ └── index.ts
│ ├── app.ts
│ ├── server.ts
├── .env
├── .gitignore
├── package.json
├── tsconfig.json
└── README.md- Response Structure Update: During the initial submission for recheck, a minor inconsistency was still present in the API response structure that I later realized. This issue has now been fixed and redeployed.