Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/ecommerce-delivery/llms.txt

Use this file to discover all available pages before exploring further.

The Ecommerce Delivery API persists all application data — users, products, sales, and push-notification tokens — in a MongoDB database accessed through Mongoose. A single environment variable (MONGODB_URL) is all that is required to establish the connection; no additional Mongoose configuration is needed for most deployments.

Connection string format

Set MONGODB_URL in your .env file to a valid MongoDB connection URI. When using MongoDB Atlas the string follows this pattern:
mongodb+srv://<user>:<pass>@<cluster>.mongodb.net/<dbname>
PlaceholderDescription
<user>Database user created in Atlas
<pass>Password for that user (URL-encode special characters)
<cluster>Atlas cluster hostname, e.g. cluster0.abc12.mongodb.net
<dbname>Name of the database to use, e.g. ecommerce
MongoDB Atlas is the recommended hosting option. The free M0 tier is sufficient for development and light production workloads. Make sure to whitelist your server’s IP address (or 0.0.0.0/0 for testing) in the Atlas Network Access settings.

How the connection works

The MongoDB() function in src/database/mongoDB.js calls mongoose.connect() with the URI from process.env.MONGODB_URL. It logs a success message to the console when the connection is established, or prints the error details if it fails:
import mongoose from "mongoose";
import dotenv from "dotenv";

dotenv.config();

const DB_URI = process.env.MONGODB_URL;
mongoose.set("strictQuery", true);

export const MongoDB = () => {
  mongoose
    .connect(DB_URI, {})
    .then(() => console.log("✅   Connected to MongoDB"))
    .catch((err) => console.error("❌ Error connected to MongoDB → ", err));
};
strictQuery: true means Mongoose will filter out query conditions that do not have a corresponding field in the schema, which prevents accidental full-collection scans from typos in query keys. Call MongoDB() once during server startup, before registering any routes that depend on the database.

Data models

The API defines four Mongoose models. Every schema is created with { timestamps: true }, which automatically adds createdAt and updatedAt fields to every document.

User

Registered platform users. Passwords are hashed with bcrypt before storage.
FieldTypeNotes
nameStringDisplay name
emailStringLogin email address
passwordStringbcrypt hash
avatarArrayUploaded avatar image objects
roles[{ name, value }]Role assignments (1 = user, 2 = admin, 3 = promotor, 4 = guest, 5 = company)
status[{ name, value }]Account status (1 = active, 2 = pending confirmation, 3 = inactive)
codeActivateString6-digit code sent by email for account verification
codeActivateExpiresDateExpiry timestamp for codeActivate
codeActivateConfirmStringConfirmation state of the activation code
codePassString6-digit code for password recovery
codePassConfirmStringConfirmation state of the password-recovery code
addressStringOptional shipping address
phone_numberStringOptional contact phone number
typeIdentificationStringOptional government ID type
identificationStringOptional government ID number
tokenStringActive session token

Product

Clothing items listed for sale.
FieldTypeNotes
userIdStringID of the admin who created the product
titleStringProduct name
descriptionStringLong-form description
priceNumberFull price
minCantNumberMinimum purchasable quantity (default 0)
discountString"Sin descuento" or "Con descuento"
priceDiscountStringDiscounted price when applicable
colorsSize[{ label, value }]Available colour options
sizes[{ label, value }]Available size options
typeShirtStringGarment cut: Overside, CropTop, Regular Fit, Semi-Overside, or Hoodie
productImgArrayUploaded product image objects
points{ cant, users[] }Like/point counter and list of users who have liked the product

Sale

Purchase orders created when a user buys a product.
FieldTypeNotes
userIdStringBuyer’s user ID
totalNumberTotal order amount
products[{ id, title, price, subtotal, productImg, discount, priceDiscount }]Snapshot of purchased items
status{ name, value }Payment status (1 = paid, 2 = pending, 3 = cancelled, 4 = validating, 5 = delivered)
deliveryStatus[{ description, date, timeHour, detail }]Ordered log of delivery tracking events
codeSaleStringUnique sale reference code
imgPayArrayPayment proof image objects
name_clientStringBuyer’s full name at time of purchase
lastName_clientStringBuyer’s last name at time of purchase
addressStringDelivery address
cityStringDelivery city
zipCodeStringPostal code
phone_numberStringContact number for delivery
emailStringBuyer’s email at time of purchase
colorsSize[{ label, value }]Colour selection for the order
sizes[{ label, value }]Size selection for the order
typeShirtStringGarment cut of the ordered item
cantBuyNumberQuantity purchased
dateproofStringDate of the payment proof
codesellerStringSeller reference code if applicable

NotificationToken

FCM device tokens used to send push notifications via Firebase Cloud Messaging.
FieldTypeNotes
userIdStringID of the owning user — required
fcmTokenStringFirebase Cloud Messaging device token — required
activeBooleanWhether the token is currently active (default true)

Build docs developers (and LLMs) love