Skip to content

JeremyAyza/api-rest-crud-mongo-db-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ Inventory Management API

RESTful API backend for inventory management system with MongoDB integration

βš™οΈ Installation β€’ πŸ”— API Endpoints β€’ ✨ Features β€’ πŸ“¦ Tech Stack


πŸ“Έ Project Overview

This is a comprehensive RESTful API built with Node.js and Express.js for managing inventory, customers, products, and sales. The API provides full CRUD operations for all entities with MongoDB as the database backend.

Note: This was one of my first backend projects, demonstrating fundamental API development skills and database integration.


πŸ“¦ Tech Stack

Technology Description
Node.js JavaScript runtime environment
Express Web application framework
MongoDB NoSQL document database
Mongoose MongoDB object modeling tool
dotenv Environment variable management
Nodemon Development server with auto-restart

✨ Features

  • πŸͺ Complete Inventory Management: Products with codes, descriptions, prices, and images
  • πŸ‘₯ Customer Management: Full customer database with contact information
  • πŸ›’ Sales System: Sales tracking with customer relationships
  • πŸ“Š Sales Details: Detailed breakdown of products sold per transaction
  • πŸ‘€ User Authentication: Basic user login system
  • πŸ”— RESTful API: Standard HTTP methods (GET, POST, PUT, DELETE)
  • πŸ“ Data Validation: Schema validation with Mongoose
  • πŸ”„ Database Relationships: Proper references between collections

πŸ—‚οΈ Database Schema

Products (producto)

  • codigo: Unique product code
  • nombre: Product name
  • descripcion: Product description
  • marca: Brand
  • precio_venta: Selling price
  • precio_compra: Purchase price
  • url_img: Product image URL
  • fecha_creacion: Creation date

Customers (cliente)

  • nombres: First name
  • apellidos: Last name
  • dni: National ID
  • email: Email address
  • celular: Phone number
  • fecha_creacion: Creation date

Sales (venta)

  • descripcion: Sale description
  • fecha_venta: Sale date
  • id_cliente: Reference to customer

Sales Details (detalleVenta)

  • cantidad: Quantity sold
  • id_producto: Reference to product
  • id_venta: Reference to sale

Users (usuario)

  • username: Username
  • password: Password
  • nombre: First name
  • apellido: Last name
  • dni: National ID
  • rpta: Active status
  • ventas: Array of sales references

πŸ”— API Endpoints

Products (/api/producto)

  • GET /api/producto - Get all products
  • GET /api/producto/:cod - Get product by code
  • POST /api/producto - Create new product
  • PUT /api/producto/:cod - Update product by code
  • DELETE /api/producto/:cod - Delete product by code

Customers (/api/cliente)

  • GET /api/cliente - Get all customers
  • GET /api/cliente/:cod - Get customer by code
  • POST /api/cliente - Create new customer
  • PUT /api/cliente/:cod - Update customer by code
  • DELETE /api/cliente/:cod - Delete customer by code

Sales (/api/venta)

  • GET /api/venta - Get all sales (with customer data)
  • GET /api/venta/:cod - Get sale by code
  • POST /api/venta - Create new sale
  • PUT /api/venta/:cod - Update sale by code
  • DELETE /api/venta/:cod - Delete sale by code

Sales Details (/api/detalleVenta)

  • GET /api/detalleVenta - Get all sale details (with product data)
  • GET /api/detalleVenta/:cod - Get sale detail by code
  • POST /api/detalleVenta - Create new sale detail
  • PUT /api/detalleVenta/:cod - Update sale detail by code
  • DELETE /api/detalleVenta/:cod - Delete sale detail by code

Users (/api/usuario)

  • GET /api/usuario - Get all users
  • GET /api/usuario/:cod - Get user by username
  • POST /api/usuario - Create new user
  • POST /api/login - User authentication
  • PUT /api/usuario/:cod - Update user by username
  • DELETE /api/usuario/:cod - Delete user by username

βš™οΈ Installation

  1. Clone the repository
git clone https://github.com/your-username/inventory-management-api
cd inventory-management-api
  1. Install dependencies
npm install
  1. Environment Setup
# Create .env file
cp .env.example .env

# Add your MongoDB connection string
MONGODB_URI=mongodb://localhost:27017/inventory_db
# or for MongoDB Atlas:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/inventory_db
  1. Start the server
# Development mode (with nodemon)
npm start

# The server will run on http://localhost:9000

πŸš€ Usage Examples

Create a Product

curl -X POST http://localhost:9000/api/producto \
  -H "Content-Type: application/json" \
  -d '{
    "codigo": "PROD001",
    "nombre": "Laptop Dell",
    "descripcion": "Laptop Dell Inspiron 15",
    "marca": "Dell",
    "precio_venta": 1200,
    "precio_compra": 1000,
    "url_img": "https://example.com/laptop.jpg"
  }'

Get All Products

curl http://localhost:9000/api/producto

Create a Customer

curl -X POST http://localhost:9000/api/cliente \
  -H "Content-Type: application/json" \
  -d '{
    "nombres": "Juan",
    "apellidos": "PΓ©rez",
    "dni": "12345678",
    "email": "juan@email.com",
    "celular": "987654321"
  }'

User Login

curl -X POST http://localhost:9000/api/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "admin",
    "password": "password123"
  }'

🎯 Project Highlights

  • RESTful Design: Follows REST API conventions
  • Database Relationships: Proper MongoDB references and population
  • Modular Structure: Clean separation of models, routes, and main app
  • Error Handling: Basic error handling with try-catch blocks
  • Data Validation: Mongoose schema validation
  • Environment Configuration: Secure environment variable management

πŸ”§ Development Notes

This project demonstrates:

  • βœ… Basic Express.js server setup
  • βœ… MongoDB integration with Mongoose
  • βœ… RESTful API design patterns
  • βœ… Database schema design
  • βœ… CRUD operations implementation
  • βœ… Environment configuration
  • βœ… Modular code organization

πŸ“ License

This project is licensed under the ISC License.


πŸ‘¨β€πŸ’» Author

Jeremy - Full Stack Developer

This was one of my first backend projects, showcasing fundamental API development skills and database integration with MongoDB.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published