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
-
POST
/login
inputusername
,password
in the request body and if the credentials are correct it will return a JWT in authorization header. -
POST
/signin
inputusername
,password
,name
in the request body and ifusername
is available and the credentials are valid it will return JWT in authorization header. -
GET
/
logout` Clears authorization header.
-
POST
/
To create a product, pass in the fieldstitle
,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 passquery
required parameter and optional parameters likeminPrice
,maxPrice
,availability
,categoryId
. -
GET
/:id
To receive a specific product passid
to get detailed information.
The secured route, using auth middleware.
-
POST
/
provideitemRef
in the request body to create an order. -
GET
/
returns all the orders of authorized user. -
GET
/:id
return detailed information about specific order.
The Secured route using auth middleware.
-
POST
/
passproductId
,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 passquantity
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.
-
POST
/
passname
,description
to add a category, returns the category id. -
GET
/
returns all categoryname
andid
. -
GET
/:id
returns detailed information about the category for the providedid
.