This project showcases the usage of Sequelize ORM (Object-Relational Mapping) with a MySQL database. It provides models for managing products, suppliers, orders, customers, and inventory.
To get started with this project, follow these steps:
Make sure you have the following installed on your machine:
- Node.js
- MySQL
-
Clone the repository:
git clone <repository-url>
-
Install dependencies:
npm install
-
Set up your environment variables:
Create a
.env
file in the root directory of the project and define the following variables:DB_HOST=<your-database-host> DB_USER=<your-database-username> DB_PASSWORD=<your-database-password> DB_NAME=<your-database-name>
-
Run the application:
npm start
The database schema consists of the following tables:
Product
: Stores information about products.Supplier
: Stores information about suppliers.Order
: Stores information about orders placed by customers.OrderItems
: Stores the items included in each order.Customer
: Stores information about customers.Inventory
: Stores inventory information for products.
Product
: Represents a product, with attributes like name, description, price, and image path.Supplier
: Represents a supplier, with attributes like name, phone, and email.Order
: Represents an order placed by a customer, with attributes like order date, status, and total quantity.OrderItems
: Represents the items included in an order, with attributes like quantity.Customer
: Represents a customer, with attributes like name, email, and phone.Inventory
: Represents the inventory of products, with attributes like quantity.
You can use the provided Sequelize models to interact with the database. For example:
const { Product, Supplier, Order, OrderItems, Customer, Inventory } = require('./models');
// Example: Create a new product
Product.create({
Name: 'Sample Product',
Description: 'This is a sample product.',
Price: 10.99,
ImagePath: '/images/sample-product.jpg'
}).then(product => {
console.log('Product created:', product.toJSON());
}).catch(error => {
console.error('Error creating product:', error);
});