/tech-store

Yo, this is demo version for my system design class

Primary LanguageJavaScript

Tech-store

Prerequisites

  • Nodejs v 18.11.0 or later (yarn or npm)
  • MySQL

Installation

  • git clone https://github.com/HOAIAN2/tech-store.git
  • cd tech-store
  • Run prepare.bat to generate .env file and install libs for server and client.
  • yarn start or npm start

Build

  • Run build.bat to build ReactJS and start server

Database Diagram

API

User routes: /api/user/

[GET] /: JWT require

  • Response
{
    "username": "username",
    "firstName": "first name",
    "lastName": "last name",
    "birthDate": "2023-02-09T01:18:02.135Z",
    "sex": "M",
    "address": "province, city, etc",
    "email": "username@email.com", // NULLABLE
    "phoneNumber": "+84....", // phone number in Vietnam, CHAR(12) NULLABLE
}

Auth routes: /api/auth/

[POST] login

  • Request
{
    "username": "username",
    "password": "password"
}
  • Response
{
    "accessToken": "string",
    "refreshToken": "string"
}

[POST] logout: JWT require

  • Request
{
    "refreshToken": "string"
}
  • Response
{
    "message": "message"
}

[POST] change-password: JWT require

  • Request
{
    "oldPassword": "string",
    "newPassword": "string",
    "refreshToken": "string"
}
  • Response

[POST] register

  • Request
{
    "username": "username",
    "firstName": "first name",
    "lastName": "last name",
    "birthDate": "2023-02-09T01:18:02.135Z",
    "sex": "M",
    "address": "province, city, etc",
    "email": "username@email.com", // NULLABLE
    "phoneNumber": "+84....", // phone number in Vietnam, CHAR(12) NULLABLE
    "password": "password"
}
  • Response
{
    "accessToken": "string",
    "refreshToken": "string"
}

[POST] refresh

  • Request
{
    "refreshToken": "string"
}
  • Response
{
    "message": "message"
}

[POST] edit: JWT require

  • Request
{
    "username": "username",
    "firstName": "first name",
    "lastName": "last name",
    "birthDate": "2023-02-09T01:18:02.135Z",
    "sex": "M",
    "address": "province, city, etc",
    "email": "username@email.com", // NULLABLE
    "phoneNumber": "+84....", // phone number in Vietnam, CHAR(12) NULLABLE
}
  • Response

[POST] upload

  • Request: formData(file: yourImage) (accept: png, jpeg, jpg)
  • Response: HTTP status code

Product routes: /api/products/

[GET]

  • Response
{
    "category": [
        {
            "productID": 1,
            "productName": "string",
            "supplier": "string",
            "category": "string",
            "price": 100000,
            "discount": null,
            "images": ["string"],
            "description": null
        }
    ]
}

[GET] product?id=number

  • Response
{
    "productID": 1,
    "productName": "string",
    "supplier": "string",
    "category": "string",
    "price": 100000,
    "discount": null,
    "images": ["string"],
    "description": null
}

[GET] suppliers-categories

  • Response
{
    "categories": [
        "category"
    ],
    "suppliers": [
        "supplier"
    ]
}

[GET] search

  • Request: query params
    • name : product name
  • Response
    • less
    [
      {
          "productID": 1,
          "productName": "string",
          "price": 100000,
          "discount": null,
          "images": ["string"],
      }
    ]

[GET] search-more

  • more
  • sortBy: price, hot, top-sell
  • star: 1->5
  • brand
  • address
  • sortMode: asc, desc
  • indexToStart:
{
  "index": 5,
  "data": [
      {
          "productID": 1,
          "productName": "string",
          "supplier": "string",
          "category": "string",
          "price": 100000,
          "discount": null,
          "images": ["string"],
          "description": null
      }
  ]
}

[POST] add-product: JWT require (token admin)

  • Request
    • form data: only send String so server gonna parse data type
    {
      "productName": "string",
      "supplier": "string",
      "category": "string",
      "price": "100000",
      "quantity": "100",
      "description": ""
    }
    • images "files": accept: jpeg, jpg, png, =< 500kbs
  • Response
{
    "productID": 1,
    "productName": "string",
    "supplier": "string",
    "category": "string",
    "price": 100000,
    "discount": null,
    "images": ["string"],
    "description": null
}

Order routes: /api/order/

[POST] create-order: JWT require

  • Request
  • Response
{
    "orderID": 1,
    "userID": 1,
    "orderDate": null,
    "paidMethod": null,
    "paid": false,
    "products": [
        {
            "productID": 3,
            "productName": "Laptop Lenovo IdeaPad Gaming 3 15IHU6 82K100FBVN (Core i7-11370H/8GB RAM/512GB SSD/15.6-in - Hàng chính hãng",
            "quantity": 6
        }
    ],
    "total": 0,
    "voucher": null
}

[POST] add-product, remove-product (Same input output) JWT require

  • Request
{
    "productID": 1,
    "quantity": 2
}
  • Response
{
    "orderID": 1,
    "userID": 1,
    "orderDate": null,
    "paidMethod": null,
    "paid": false,
    "products": [
        {
            "productID": 3,
            "productName": "Laptop Lenovo IdeaPad Gaming 3 15IHU6 82K100FBVN (Core i7-11370H/8GB RAM/512GB SSD/15.6-in - Hàng chính hãng",
            "quantity": 6
        },
        {
            "productID": 4,
            "productName": "Laptop Acer Nitro 5 AN515-45-R6EV R5-5600H |8GB|512GB|GTX 1650 4GB|156 FHD 144Hz|Win 11 Hàng chính hãng",
            "quantity": 3
        },
        {
            "productID": 7,
            "productName": "Laptop Lenovo Legion 5 15IAH7 82RC003WVN |i5-12500H|8GB|512GB|RTX 3050 Ti|Win11- Hàng chính hãng",
            "quantity": 3
        }
    ],
    "total": 0,
    "voucher": null
}

[POST] make-payment: JWT require

  • Request
{
    "paymentMethod": 1
}
  • Response
{
    "orderID": 1,
    "userID": 1,
    "orderDate": "2023-04-21T11:28:22.000Z",
    "paidMethod": "Electronic bank transfers",
    "paid": true,
    "products": [
        {
            "productID": 4,
            "productName": "Laptop Acer Nitro 5 AN515-45-R6EV R5-5600H |8GB|512GB|GTX 1650 4GB|156 FHD 144Hz|Win 11 Hàng chính hãng",
            "quantity": 3,
            "price": 18790000,
            "discount": null
        },
        {
            "productID": 7,
            "productName": "Laptop Lenovo Legion 5 15IAH7 82RC003WVN |i5-12500H|8GB|512GB|RTX 3050 Ti|Win11- Hàng chính hãng",
            "quantity": 3,
            "price": 32150400,
            "discount": null
        }
    ],
    "total": 152821200,
    "voucher": null
}

[POST] set-voucher JWT require

  • Request
{
    "voucherID": "string"
}
  • Response
{
    "orderID": 1,
    "userID": 1,
    "orderDate": null,
    "paidMethod": null,
    "paid": 0,
    "products": [
        {
            "productID": 3,
            "productName": "Laptop Lenovo IdeaPad Gaming 3 15IHU6 82K100FBVN (Core i7-11370H/8GB RAM/512GB SSD/15.6-in - Hàng chính hãng",
            "quantity": 6
        },
        {
            "productID": 4,
            "productName": "Laptop Acer Nitro 5 AN515-45-R6EV R5-5600H |8GB|512GB|GTX 1650 4GB|156 FHD 144Hz|Win 11 Hàng chính hãng",
            "quantity": 3
        },
        {
            "productID": 7,
            "productName": "Laptop Lenovo Legion 5 15IAH7 82RC003WVN |i5-12500H|8GB|512GB|RTX 3050 Ti|Win11- Hàng chính hãng",
            "quantity": 3
        }
    ],
    "total": 0,
    "voucher": {
        "voucherID": "string",
        "voucherName": "string",
        "voucherDiscount": 0.2,
        "expiryDate": "date time",
        "description": "date"
    }
}

Comment routes: /api/comment/

[GET] ?productID=1&sortMode=DESC

  • Respone
[
    {
        "commentID":1,
        "userID": 1,
        "avatar":"1682648528080-hoaian_admin.jpeg",
        "userFirstName":"Hoài Ân",
        "userLastName":"",
        "productID":1,
        "comment":"test comment xem nó hiển thị ra sao\n:))))))))",
        "rate":null,
        "commentDate":"2023-04-27T17:00:00.000Z"
    }
]

[POST] /:id JWT require

  • Request
{
    "content": "string"
}

[DELETE] / JWT require

  • Request: ?commentID?productID
  • Respone: HTTP status code

Rating routes: /api/rating/

[GET] /:productID JWT require

  • Respone
{
    "rate": 3
}

[POST] JWT require

  • Request
{
    "productID": 1,
    "rate": 3
}