Skip to content

This project is a Node.js application built with Express.js and MongoDB, designed to provide a backend for an e-commerce platform. It includes models for managing products, categories, brands, carts, orders, users, reviews, and coupons. Additionally, it features utility classes for error handling and implementing common MongoDB query functionalitie

Notifications You must be signed in to change notification settings

Imtoord/E-commerce

Repository files navigation

Overview

This project is a Node.js application built with Express.js and MongoDB, designed to provide a backend for an e-commerce platform. It includes models for managing products, categories, brands, carts, orders, users, reviews, and coupons. Additionally, it features utility classes for error handling and implementing common MongoDB query functionalities.

Project Structure

The project consists of several modules organized into folders:

Models

Contains MongoDB schema definitions and models for various entities such as products, categories, brands, carts, orders, users, reviews, and coupons.

Utils

Includes utility classes for error handling (ErrorHandler) and implementing common MongoDB query features (ApiFeatures).

Utils/Validator

Designed validator functions to validate incoming data and ensure data integrity. Implemented validation middleware to validate request data before processing.

Controller and Middleware

Developed controller functions to handle incoming requests and interact with the database. Implemented middleware functions for request validation, authentication, and error handling.

Models

Product

Represents a product with attributes like title, description, price, quantity, and associated entities like category, brand, and reviews.

Category

Defines product categories with attributes such as name and image.

Brand

Represents brands with attributes like name and image.

Cart

Represents user carts with details about the products, quantities, prices, and total prices.

Order

Represents user orders with details like cart items, payment method, and delivery status.

User

Represents users with attributes like username, email, password, addresses, and wishlist.

Review

Represents product reviews with attributes like title, rating, user, and product association.

Coupon

Represents discount coupons with attributes like name, expiration date, and discount percentage.

SubCategory

Defines subcategories associated with parent categories.

Utilities

ErrorHandler

Provides a custom error class for handling errors with status codes.

ApiFeatures

Offers utility methods for pagination, sorting, filtering, field selection, and searching in MongoDB queries.

Usage

  1. Clone the repository from GitHub.
  2. Install dependencies using npm install.
  3. Set up environment variables like MongoDB URI, JWT secret key, and expiration time.
  4. Run the application using npm start.

Topics

1. Authentication and Authorization

2. Product Management

3. Order Management

4. Cart Management

5. Reviews and Ratings

6. Coupon and Discount Management

7. Category and Subcategory Management

8. Pagination, Sorting, and Filtering

9. Error Handling and Utilities

10. User Profile and Wishlist

Routes

1. User Authentication

2. Product Management

3. Order Management

4. Cart Management

5. Reviews and Ratings

6. Coupon and Discount Management

7. Category and Subcategory Management

8. Other Features

Category Routes

  • GET /api/categories: Get all categories.
  • POST /api/categories: Create a new category.
  • GET /api/categories/:id: Get a specific category by ID.
  • PUT /api/categories/:id: Update a specific category by ID.
  • DELETE /api/categories/:id: Delete a specific category by ID.
  • GET /api/categories/:categoryId/subcategories: Get all subcategories of a specific category.
  • GET /api/categories/:categoryId/products: Get all products of a specific category.

Subcategory Routes

  • GET /api/subcategories: Get all subcategories.
  • POST /api/subcategories: Create a new subcategory.
  • GET /api/subcategories/:id: Get a specific subcategory by ID.
  • PUT /api/subcategories/:id: Update a specific subcategory by ID.
  • DELETE /api/subcategories/:id: Delete a specific subcategory by ID.

Brand Routes

  • GET /api/brands: Get all brands.
  • POST /api/brands: Create a new brand.
  • GET /api/brands/:id: Get a specific brand by ID.
  • PUT /api/brands/:id: Update a specific brand by ID.
  • DELETE /api/brands/:id: Delete a specific brand by ID.

Product Routes

  • GET /api/products: Get all products.
  • POST /api/products: Create a new product.
  • GET /api/products/:id: Get a specific product by ID.
  • PUT /api/products/:id: Update a specific product by ID.
  • DELETE /api/products/:id: Delete a specific product by ID.
  • GET /api/products/search: Search for products.

Review Routes

  • GET /api/products/:productId/reviews: Get all reviews for a specific product.
  • POST /api/products/:productId/reviews: Create a new review for a specific product.
  • GET /api/reviews/:id: Get a specific review by ID.
  • PUT /api/reviews/:id: Update a specific review by ID.
  • DELETE /api/reviews/:id: Delete a specific review by ID.

User Routes

  • GET /api/users/me: Get the authenticated user's details.
  • PUT /api/users/updateUser: Update the authenticated user's details.
  • PUT /api/users/changePassword: Change the authenticated user's password.
  • GET /api/users: Get all users (admin only).
  • POST /api/users: Create a new user (admin only).
  • GET /api/users/:id: Get a specific user by ID (admin only).
  • PUT /api/users/:id: Update a specific user by ID.
  • DELETE /api/users/:id: Delete a specific user by ID (admin only).

Authentication Routes

  • POST /api/auth/signup: Register a new user.
  • POST /api/auth/login: Login with credentials.
  • DELETE /api/auth/logout: Logout the authenticated user.

Cart Routes

  • GET /api/addToCarts: Get logged-in user's cart.
  • POST /api/addToCarts: Add a product to the cart.
  • DELETE /api/addToCarts: Clear logged-in user's cart.
  • DELETE /api/addToCarts/:id: Delete a specific item from the cart.
  • PUT /api/addToCarts/:id: Update a specific item in the cart.
  • PUT /api/addToCarts/applycoupon: Apply coupon to the cart.

Wishlist Routes

  • POST /api/wishList: Add a product to the wishlist.
  • DELETE /api/wishList/:productId: Remove a product from the wishlist.
  • GET /api/wishList: Get logged-in user's wishlist.

Address Routes

  • POST /api/addresses: Add an address for the logged-in user.
  • DELETE /api/addresses/:addressId: Remove an address for the logged-in user.
  • GET /api/addresses: Get all addresses of the logged-in user.

Coupon Routes

  • GET /api/coupons: Get all coupons.
  • POST /api/coupons: Create a new coupon.
  • GET /api/coupons/:id: Get a specific coupon by ID.
  • PUT /api/coupons/:id: Update a specific coupon by ID.
  • DELETE /api/coupons/:id: Delete a specific coupon by ID.

Forget Password Routes

  • POST /api/forgetpassword: Check password for reset.
  • GET /api/forgetpassword/:email/:token: Reset password page.
  • POST /api/forgetpassword/:email/:token: Update reset password.

Utilities

ErrorHandler

Provides a custom error class for handling errors with status codes.

ApiFeatures

Offers utility methods for pagination, sorting, filtering, field selection, and searching in MongoDB queries.

Usage

  1. Clone the repository from GitHub.
  2. Install dependencies using npm install.
  3. Set up environment variables like MongoDB URI, JWT secret key, and expiration time.
  4. Run the application using npm start.

About

This project is a Node.js application built with Express.js and MongoDB, designed to provide a backend for an e-commerce platform. It includes models for managing products, categories, brands, carts, orders, users, reviews, and coupons. Additionally, it features utility classes for error handling and implementing common MongoDB query functionalitie

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published