nvkex / e-comm-backend-proto

๐Ÿ—œA backend prototype for E-Commerce sites.

Home Page:https://e-comm-proto.herokuapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

E-Commerce API

Disclaimer

This API can be used to perform all types of operations related to an e-commerce website

Base URL

https://e-comm-proto.herokuapp.com/

Routes

1. Login

Method : POST

URL : https://e-comm-proto.herokuapp.com/auth/login

Auth Required : false

Body :

Key Description Optional Type
email User email No String
password User password No String

Response Data :

{
    // User data
    "user" : [Object]
}

Response Header :

{
    // Authorization Token
    "auth-token" : [String]
}

Errors :

  • Unregistered user tries to login.
{
    "error" : "User doesnt exist"
}
  • Incorrect password.
{
    "error" : "Invalid Password"
}

2. Signup

Method : POST

URL : https://e-comm-proto.herokuapp.com/auth/signup

Auth Required : false

Body :

Key Description Optional Type
email User email No String
password User password No String
name User's name No String

Response Data :

{
    // On successful signup
    "msg" : [String]
    // On signup failure
    "error": [String]
}

Note : A welcome mail will be sent to the user on successful signup.

Errors :

  • Existing user signs up.
{
    "error" : "Email already exists"
}
  • Other errors
{
    // Error generated by NodeJS/MongoDB
    "error" : [Object]
}

3. Get Authentication History (Admin)

Method : GET

URL : https://e-comm-proto.herokuapp.com/admin/auth-history

Auth Required : true

User Role : Admin

Request Header :

Key Description Optional Type
x-access-token Auth Token No String

Response Data :

{
    // Authentication history
    "data" : {
        "date" : [Date],
        "history" : [Array]
    }
}

Errors :

  • When user has not logged in or is not an admin.
{
    "message" : "Unauthorized"
}
  • Other errors
{
    // Error generated by NodeJS/MongoDB
    "message" : [Object]
}

3. Get Transaction History (Admin)

Method : GET

URL : https://e-comm-proto.herokuapp.com/admin/transaction-history

Auth Required : true

User Role : Admin

Request Header :

Key Description Optional Type
x-access-token Auth Token No String

Response Data :

{
    // Buy & Sell transaction history
    "data" : [Object]
}

Errors :

  • When user has not logged in or is not an admin.
{
    "message" : "Unauthorized"
}
  • Other errors
{
    // Error generated by NodeJS/MongoDB
    "message" : [Object]
}

4. Buy Product

Method : POST

URL : https://e-comm-proto.herokuapp.com/user/buy

Auth Required : true

Request Header :

Key Description Optional Type
x-access-token Auth Token No String

Request Body :

Key Description Optional Type
productId Product ID No ObjectID
coupon Coupon Code Yes String
sender.id Buyer's ID No ObjectID
sender.name Buyer's name No String
sender.email Buyer's email No String
sender.location Buyer's Location Yes Co-ordinates
recipient.id Seller's ID No ObjectID
recipient.name Seller's name No String
recipient.email Seller's email No String
recipient.location Seller's Location Yes Co-ordinates

Response Data :

{
    // Transaction Date
    "date" : [Date],
    // Coupon code
    "coupon" : [String],
    // Transaction status
    "success" : [Boolean],
    // Product ID
    "productId" : [ObjectID],
    // Buyer's Info
    "sender": {
        "id": [ObjectID],
        "name": [String],
        "email": [String]
    },
    // Seller's Info
    "recipient": {
        "id": [ObjectID],
        "name": [String],
        "email": [String]
    },
    // Transaction ID
    "id": [ObjectID],
    // Trnasaction Type
    "transactionType": [String],
}

Errors :

  • If auth token is not provided in header.
{
    "message" : "No token provided!"
}
  • If user has not logged in.
{
    "message" : "Unauthorized"
}
  • Other errors
{
    // Error generated by NodeJS/MongoDB
    "message" : [Object]
}

Error Responses

Code : 400 Bad Request

Content : Mongoose error is shown, with suggestions to fix the query.

About

๐Ÿ—œA backend prototype for E-Commerce sites.

https://e-comm-proto.herokuapp.com


Languages

Language:JavaScript 100.0%