This project is a simple e-commerce backend built with TypeScript, Express, PostgreSQL, and TypeORM. It follows the MVC architecture and includes CRUD operations for managing products and their variants.
- Node.js
- npm
- PostgreSQL
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Install dependencies:
npm install
-
Set up the PostgreSQL database:
- Create a new PostgreSQL database.
- Update the .env file with your database configuration.
-
Start the application:
npm start
The application will be running on http://localhost:8000.
Products:
-
Get all products:
GET localhost:8000/products
-
Get a specific product:
GET localhost:8000/products/:id
-
Create a new product:
POST localhost:8000/products
Request Body
{ "name": "Product Name", "description": "Product Description", "price": 34.59, "inventory": 45 }
-
Update a product:
PUT localhost:8000/products/:id
Request Body
{ "name": "Updated Product Name", "description": "Updated Product Description", "price": 55.99, "inventory": 55 }
-
Delete a product:
DELETE localhost:8000/products/:id
Variants:
- Get all variants for a product:
GET localhost:8000/products/:productId/variants
- Get a specific variant:
GET localhost:8000/products/:productId/variants/:variantId
- Create a new variant:
Request Body
POST localhost:8000/products/:productId/variants
{ "name": "Variant Name", "price": 50, "inventory": 20 }
- Update a variant:
Request Body
PUT localhost:8000/products/:productId/variants/:variantId
{ "name": "Updated Variant Name", "price": 70, "inventory": 30 }
- Delete a variant:
DELETE localhost:8000/products/:productId/variants/:variantId