(GDSC Project) This project aims to connect sellers with customers in an interactive and secured ecommerce platform. The API comprises of endpoints related to customer and seller authentication, and the creation, management and deletion of products and orders from the database.
- Node.js
- Typescript
- Express and Mongoose
- MongoDB Atlas (https://www.mongodb.com/atlas)
- Joi (for server-side schema validation)
- Bcrypt (for password hashing)
- UUID (for creating secure IDs)
- Nodemon (for development)
- Clone the project
git clone https://github.com/krshishir1/NextGenShopAPI.git
cd NextGenShopAPI/
npm install
- Setup environment variables
mv .env.example .env
-
Add required details in the .env file. You will require MongoDB uri which can be accessed from MongoDB Atlas.
-
Running the project
// starts nodemon development server
npm run dev
// creates dist folder (for production)
npm run build
npm run start
The API provides a platform with the following functionalities:
- Sellers and customers can register, log in, and receive unique IDs. Sellers can manage their profiles, change passwords, and delete their accounts.
- Sellers can create, update, and delete products, but only with a valid seller ID.
- Products can be read and filtered by anyone based on price and category.
- Customers can also manage their profiles, change passwords, delete their accounts, and create and update orders.
- Completing an order automatically updates the relevant products in the products collection.
- Only admins have the authority to create, update, and delete categories.
This API endpoint comprises of registration, login, update, deletion and altering the password of a new seller.
POST /api/sellers/register
Content-Type: application/json
{
"name": "Raymonds",
"email": "[email protected]",
"password": "<password>"
}
Usage: Signs up a new seller
POST /api/sellers/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "<password>"
}
Usage: Login a seller
PUT /api/sellers/update
Authorization <sellerId>
Content-Type: application/json
{
name: "Raymonds",
email: "[email protected]"
},
Usage: Update seller info
PATCH /api/sellers/change-password
Authorization <sellerId>
Content-Type: application/json
{
password: "<new-password>"
},
Usage: Change seller password
DELETE /api/sellers/delete-account
Authorization <sellerId>
Usage: Delete a seller account
GET /api/sellers/get-account
Authorization <sellerId>
Usage: Get seller account info
GET /api/sellers/get-sellers
Usage: Get all sellers
This API comprises of endpoints for creation, update and deletion of products. Only a valid seller can create products.
POST /api/products/new
Authorization <sellerId>
Content-Type: application/json
{
"name": "iPhone 12",
"price": 799,
"category": "Electronics",
"description": "A new iPhone 12",
"inventoryCount": 100
"sellerId": "<sellerId>"
}
Usage: Create a new product
PUT /api/products/:productId
Authorization <sellerId>
Content-Type: application/json
{
"name": "iPhone 12",
"price": 599,
"category": "Electronics",
"description": "A new iPhone 12",
"inventoryCount": 95
}
Usage: Update a product by its id
DELETE /api/products/:productId
Authorization <sellerId>
Usage: Delete a product by its id
GET /api/products/:productId
Authorization <sellerId>
Usage: Get a product by its id
GET /api/products
Authorization <sellerId>
Usage: Get all products of a seller
GET /api/products/filter/price?maxPrice=1000&minPrice=500
Usage: Filter products by price
GET /api/products/filter/category?category=Electronics
Usage: Filter products by category
POST /api/categories/new
Content-Type: application/json
{
"name": "Electronics",
"description": "All electronic items"
}
Usage: Create a new category and stores it in catogories collection
PUT /api/categories/:categoryId
Content-Type: application/json
{
"name": "Electronics",
"description": "All mobile accessories"
}
Usage: Update a category by its id
DELETE /api/categories/:categoryName
Usage: Delete a category by its name
GET /api/categories/:categoryId
Usage: Get a category by its id
GET /api/categories
Usage: Get all categories
This API endpoint comprises of registration, login, update, deletion and altering the password of a new customer.
POST /api/customers/register
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"password": "<password>"
}
Usage: Signs up a new customer
POST /api/customers/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "<password>"
}
Usage: Login a customer
PUT /api/customers/update
Authorization <customer-email>
Content-Type: application/json
{
"firstName": "John",
"lastName": "Donut",
}
Usage: Update customer info
PATCH /api/customers/change-password
Authorization: <customer-email>
Content-Type: application/json
{
"password": "<new-password>"
}
Usage: Change customer password
DELETE /api/customers/delete-account
Authorization <customer-email>
Usage: Delete a customer account
GET /api/customers/get-account
Authorization <customer-email>
Usage: Get customer account details
GET /api/customers/get-customers
Usage: Get all customers
This API comprises of endpoints related to creation, update and delete of orders. Orders document can controlled and altered only by a valid customer
POST /api/orders/new
Content-Type: application/json
Authorization: <customer-email>
{
customerInfo: <customer-email>,
products: [
{
productId: "<product-id>",
quantity: 2
}
]
}
Usage: Create a new order by adding products assigned by the customer
PATCH /api/orders/:orderId/product/add
Content-Type: application/json
Authorization : <customer-email>
{
productId: "<product-id>",
quantity: 1
}
Usage: Add a product to an existing order
PATCH /api/orders/:orderId/product/add
Content-Type: application/json
Authorization : <customer-email>
{
productId: "<product-id>",
quantity: 1
}
Usage: Delete a product from an existing order
PATCH /api/orders/:orderId/complete
Authorization <customer-email>
Usage: Changes the status of an order to "completed"
PATCH /api/orders/:orderId/cancel
Authorization <customer-email>
Usage: Changes the status of an order to "cancelled"
DELETE /api/orders/:orderId
Authorization: <customer-email>
Usage: Delete an order by its id
GET /api/orders/:orderId
Authorization <customer-email>
Usage: Get an order by its id
GET /api/orders
Authorization <customer-email>
Usage: Get all orders of a customer