Giter Site home page Giter Site logo

kayleriegerpatton / ecommerce-back-end Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 44 KB

Node.js application using an Express.js server and a MySQL database through the sequelize package. Manages category, product, and tag data.

License: MIT License

JavaScript 100.00%
ecommerce mysql-database sequelize express

ecommerce-back-end's Introduction

E-commerce Back-End

Table of Contents

Description

This Node.js application uses an Express.js server and a MySQL database through the sequelize package.

The database contains 4 tables: categories, products, tags, and product_tags. The api queries the 3 main tables, each with 5 endpoints.

Built With

  • Node.js
  • Express.js
  • MySQL
  • sequelize, moment.js & colors packages

Endpoints

POST /api/{categories|products|tags}

  • creates a new record by type

Post body example (products):

{
  "product_name": "The Beatles Abbey Road, Special Edition CD",
  "price": 25.99,
  "stock": 30,
  "category_id": 3,
  "tagIds": [1, 3]
}

Sample response:

{
  "success": true,
  "data": "Created new product."
}

PUT /api/{categories|products|tags}/:id

  • updates a record by id

Post body example (products):

{
  "product_name": "The Beatles Abbey Road CD",
  "price": 13.99,
  "stock": 3,
  "tagIds": [1, 3, 4]
}

Sample response:

{
  "success": true,
  "data": "Updated product to The Beatles Abbey Road CD."
}

DELETE api/{categories|products|tags}/:id

  • deletes a record by id

Sample response (products):

{
  "success": true,
  "data": "Product with id 15 deleted."
}

GET api/{categories|products|tags}

  • returns a list of all records by type

Sample response (categories):

{
  "success": true,
  "allCategories": [
    {
      "id": 1,
      "category_name": "Shirts",
      "products": [
        {
          "id": 1,
          "product_name": "Plain T-Shirt",
          "price": "14.99",
          "stock": 14,
          "category_id": 1
        },
        {
          "id": 9,
          "product_name": "V-Neck",
          "price": "14.38",
          "stock": 3,
          "category_id": 1
        }
      ]
    },
    {
      "id": 2,
      "category_name": "Shorts",
      "products": [
        {
          "id": 5,
          "product_name": "Cargo Shorts",
          "price": "29.99",
          "stock": 22,
          "category_id": 2
        },
      ]
    },

GET /api/{categories|products|tags}/:id

  • returns a record by id

Response (tags):

        {
            "id": 4,
            "tag_name": "red",
            "products": [
                {
                    "id": 3,
                    "product_name": "Branded Baseball Hat",
                    "price": "22.99",
                    "stock": 12,
                    "category_id": 4,
                    "product_tag": {
                        "id": 7,
                        "product_id": 3,
                        "tag_id": 4,
                        "productId": 3,
                        "tagId": 4
                    }
                },
                {
                    "id": 10,
                    "product_name": "Converse High Tops",
                    "price": "70.00",
                    "stock": 25,
                    "category_id": 5,
                    "product_tag": {
                        "id": 19,
                        "product_id": 10,
                        "tag_id": 4,
                        "productId": 10,
                        "tagId": 4
                    }
                }
            ]
        },

Getting Started

Installation

$ git clone https://github.com/kayleriegerpatton/ecommerce-back-end.git
$ cd ecommerce-back-end
$ npm install

Environment Variables

In the root folder, add an .env file following the structure below:

DB_NAME=''
DB_USER=''
DB_PASSWORD=''
DB_HOST=''

Database Setup

Create the ecommerce_db database using the schema.sql file in the terminal or MySQL Workbench:

DROP DATABASE IF EXISTS ecommerce_db;

CREATE DATABASE ecommerce_db;

Seed the data:

$ npm run seed

Launch the App

$ npm run start

Demo Video

Click to view the app demo video.

Questions

To contribute to or ask a question about this project, please email me.

ecommerce-back-end's People

Contributors

kayleriegerpatton avatar surajverma2587 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.