This is an API for managing an inventory system, built with Node.js, Express, and MongoDB. It allows users to manage products, sales, and users with role-based access control (RBAC) for employees and managers.
- Features
- Technologies Used
- Installation
- Environment Variables
- API Endpoints
- CRUD operations for products, sales, and users
- Role-based access control (RBAC):
- Employees can only retrieve data
- Managers can retrieve, create, update and delete data but can not get user data or delete user data
- Admins can perform CRUD operations on entire database and get and delete users
- User authentication via JWT
- Input validation using middleware
- Error handling with custom error messages
- MongoDB as the database for managing data
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT (JSON Web Tokens) for authentication
- bcrypt.js for password hashing
- dotenv for managing environment variables
- Node.js and npm installed
- MongoDB installed or a MongoDB cloud instance
- Clone the repository:
git clone https://github.com/yourusername/inventory-management-api.git
- Navigate to the project directory:
cd inventory-management-api
- Install the required dependencies:
npm install
-
Set up the environment variables (see Environment Variables).
-
Start the server:
npm start
Create a .env file in the root directory and configure the following variables:
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
- POST /login
- POST /reigster
- GET /
- GET /:userID
- DELETE /:userID
- Body:
{ "name" : "Bob", "email": "bob@gmail.com", "password": "test1234", "role": "admin" }
- POST /
- GET /
- GET /:saleID
- DELETE /:saleID
- PATCH /:saleID
- Body:
{ "productID" : "66a6f3ce0acb797bdd533dae", "quantity": "2", "sold_for": "14.29" }
- POST /
- GET /
- GET /:productID
- DELETE /:productID
- PATCH /:productID
- Body:
{ "name" : "Bobby", "description": "real bobby", "price": "12.99", "quantity": "5", "category": "snack", "supplier": "Bob" }