/E-Commerce-Back-End

Creating a back end for an e-commerce site by configuring Express.js API to use Sequelize to interact with a MySQL database

Primary LanguageJavaScriptMIT LicenseMIT

License: MIT

lang repo size last commit

E-Commerce-Back-End

Description

In this app, a backend was built for an e-commerce site. Using Sequelize to interact with a MySQL database and Express.js API, we can GET, PUT, POST and DELETE from the database's tables. The database has the following tables: Category, Product, Tag and ProductTag as an association table. The routes were tested using Insomnia Core.

Table of Contents

Installation

  • Go to the app's repo in github and clone the app

  • Open the app in VS code, navigate to .env file, change the DB_USER and DB_PW based on current user configurations

  • From terminal: navigate to app's directoty and run:

    $ npm install
  • From terminal: navigate to db folder in the app's directoty and run:

    $ mysql -uroot - p
  • Run the schema file:

    source schema.sql
  • From terminal: navigate to the app's directoty and run:

    $ npm run seed
  • To invoke the app from terminal, run:

    $ node server.js

Usage

Below are some screenshots demonstrating testing the routes in Insomnia

GET routes

  • Categroy

Category

  • Product

Product

  • Tag

Tag

POST routes

  • Categroy

Category

  • Product

Product

  • Tag

Tag

PUT routes

  • Categroy

Category

  • Product

Product

  • Tag

Tag

Demo

Features

The tables have association established in Sequelize models to create the following relationships: Product belongs to Category, and Category has many Product models. Product belongs to many Tag models, and Tag belongs to many Product models. Products can have multiple tags and tags to have many products by using a ProductTag model.

Tests

To test the functionality of the routes, open Insomnia, specifiy the method in the request and enter the URL to be tested: Sincd the app uses app router, to GET routes for all the categories for example, enter URL http://localhost:3001/api/categories/ and hit send. The GET all products URL is http://localhost:3001/api/products, and GET all tags URL is http://localhost:3001/api/tags

Built With

Resources Used

Author

Iman Mansour

License

This project is licensed under the MIT License