Basic backend for ecommerce platform.
Packages used - bcrypt, jsonwebtoken, express.js, mongoose also typescript is used to maintain type safety in code.
To test this project convert sampleenv
file to .env
and change variables.
Also, you to test it with postman, import thunder-collection_ecom_postman.json
file in a Postman environment.
Models are defined along with corresponding interfaces to maintain type safety in the codebase.
Defined functionalities in the separate files from route files for a neat and readable codebase.
MongoDB database is used along with Mongoose ODM to maintain schema.
Using express.js allows us to deliver robustly and also modularise code in separate files. All different routes are defined in their corresponding file. Also middleware
/auth
POST
/login
input username
, password
in the request body and if the credentials are correct it will return a JWT in authorization header.
POST
/signin
input username
, password
, name
in the request body and if username
is available and the credentials are valid it will return JWT in authorization header.
GET
/
logout` Clears authorization header.
/product
POST
/
To create a product, pass in the fields title
, availability
, categoryId
, description
, price
.
DELETE
/:id
only authorized users can delete a product
To delete a product from the database pass in the product id.
GET
/
To get the list of products pass query
required parameter and optional parameters like minPrice
, maxPrice
, availability
, categoryId
.
GET
/:id
To receive a specific product pass id
to get detailed information.
/order
The secured route, using auth middleware.
POST
/
provide itemRef
in the request body to create an order.
GET
/
returns all the orders of authorized user.
GET
/:id
return detailed information about specific order.
/cart
The Secured route using auth middleware.
POST
/
pass productId
, quantity
in the request body to add product in the authorized user cart.
GET
/
returns all products in the authorized user cart.
PUT
/:id
update the quantity of a specific product pass quantity
in the query. It will increment the previous value by given value.
DELETE
/
clear the cart of the authorized user.
DELETE
/:id
remove a particular product from user's cart.
/category
POST
/
pass name
, description
to add a category, returns the category id.
GET
/
returns all category name
and id
.
GET
/:id
returns detailed information about the category for the provided id
.