GithubHelp home page GithubHelp logo

orm-ecommerce-back-end's Introduction

ORM: eCommerce Back-End

Description

The back end for an Object Relational Mapping (ORM) eCommerce site by modifying starter code using Express.js API to use Sequelize to interact with a MySQL database. Use Insomnia to check all routes.

Installation

Initializer

npm init

MySQL2 CLI to connect to the SQL database and perform queries.

npm install --save mysql2

Sequalize

npm install sequelize

To hide password using .env file

npm install dotenv --save

To Install Insomnia Insomnia is not installed as a CLI but it it a program used for opening API routes.

Usage

To activate SQL Terminal.

mysql -u root -p

Run schema file in SQL server.

source db/schema.sql

Exit SQL Terminal.

exit

Run the following commands in the Node Terminal.

npm run seed
npm start

Items Completed

✅A functional Express.js. API in which a database name, MySQL username, and MySQL password to an environment variable.

✅Can connect to the database using Sequelize and run schema and seed commands.

✅Development database is created and is seeded with test data.

✅Command prompt invokes the application so the server is started and the Sequelize models are synced to the MySQL database

✅Open API GET routes in Insomnia for categories, products, or tags so the data for each of these routes is displayed in a formatted JSON

GET Categories

localhost:3001/api/categories

GET Products

localhost:3001/api/products

GET tags

localhost:3001/api/tags

✅Open API GET routes to return a single category, a single product, and a single tag being tested in Insomnia

GET Category by ID

localhost:3001/api/categories/1

GET Products Get One

localhost:3001/api/products/1

GET tags by ID

localhost:3001/api/tags/1

✅Test API POST, PUT, and DELETE routes in Insomnia to successfully create, update, and delete data in my database. Repeat the below walkthrough with Products & tags.

DELETE Categories: Delete Category by ID

localhost:3001/api/categories/6

POST Categories: Create Category

localhost:3001/api/categories

PUT Categories: Update Category

localhost:3001/api/categories/6

Walkthrough Videos:

ORM.create.seeds.schema.database.webm
ORM.eCommerce.Insomnia.Demo.webm

Screenshot

Database Models

  • Category

    • id

      • Integer.

      • Doesn't allow null values.

      • Set as primary key.

      • Uses auto increment.

    • category_name

      • String.

      • Doesn't allow null values.

  • Product

    • id

      • Integer.

      • Doesn't allow null values.

      • Set as primary key.

      • Uses auto increment.

    • product_name

      • String.

      • Doesn't allow null values.

    • price

      • Decimal.

      • Doesn't allow null values.

      • Validates that the value is a decimal.

    • stock

      • Integer.

      *** Does** allow null values for deletion.

      • Set a default value of 10.

      • Validates that the value is numeric.

    • category_id

      • Integer.

      • References the Category model's id.

  • Tag

    • id

      • Integer.

      • Doesn't allow null values.

      • Set as primary key.

      • Uses auto increment.

    • tag_name

      • String.
  • ProductTag

    • id

      • Integer.

      • Doesn't allow null values.

      • Set as primary key.

      • Uses auto increment.

    • product_id

      • Integer.

      • References the Product model's id.

    • tag_id

      • Integer.

      • References the Tag model's id.

Associations

  • Product belongs to Category, and Category has many Product models, as a category can have multiple products but a product can only belong to one category.

  • Product belongs to many Tag models, and Tag belongs to many Product models. Allow products to have multiple tags and tags to have many products by using the ProductTag through model.

Fill Out the API Routes to Perform RESTful CRUD Operations

Fill out the unfinished routes in product-routes.js, tag-routes.js, and category-routes.js to perform create, read, update, and delete operations using your Sequelize models.

Note that the functionality for creating the many-to-many relationship for products has already been completed for you.

Hint: Be sure to look at the mini-project code for syntax help and use your model's column definitions to figure out what req.body will be for POST and PUT routes!


License: MIT

orm-ecommerce-back-end's People

Contributors

cynthiagodoy avatar

Watchers

 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.