/OMS

Primary LanguageTypeScript

Order Management System

📝 Table of Contents

📙 About

Designing and implementing an Order Management System (OMS) for our e-commerce mobile app using NestJS for the framework, PostgreSQL for the database, and Prisma as the Object-Relational Mapping (ORM).

📃 System Description

The System has the following APIs :

1-Add Product to Cart

This API adds a product to a specific user's cart or increment product's quantity if it already exists in the cart. It requires both the user ID and product ID.It checks for the product stock before it is added to the cart. It fails if either the product or user is not found, if validation fails, or if the product is out of stock (i.e., has zero stock).

2-Remove Product from Cart

This API removes a product from a specific user's cart. It requires both the user ID and the product ID. It fails if either the user or product cannot be found, or if validation fails.

3-Get User's Cart

This API retrieves the cart of a specific user. It requires the user ID . It fails if the user or is not found, or if validation fails.

4-Update Cart Item Quantity

This API updates the quantity of a product in the cart of a specific user. It requires the user ID, the product ID and the product's quantity.It checks for the product stock before its quantity is updated. It fails if either the user or product cannot be found, if validation fails or if the product is not available in the required quantity.

5-Get Order Details

This API fetches details of a specific order by its ID. It fails if the order is not found or if validation fails.

6-Update Order Status

This API updates the status of an order by its ID.The allowed status are : Pending , Delivering , Delivered or Canceled. It fails if the order is not found or if validation fails. If the order is canceled all the products in it are returned(their stocks are increased).

7-Create Order

This API creates a new order from the user's cart. It requires the user ID. It checks for every product stock in the order before the order is created.If it succeeds the cart is emptied , every produc stock is decreased and the order is created. It fails if the user is not found, if validation fails or if the product is not available in the required quantity.

8-Apply Coupon to Order

This API applies a coupon code to reduce the total price of an order. It requires the order ID and the coupon code. It fails if either the order or coupon code cannot be found, if validation fails or if the coupon has expired.

9-Get User Orders

This API retrieves all orders for a specific user.It requires the user ID. It fails if the user is not found or if validation fails.

🏁 Getting Started

This is a list of needed instructions to run the project locally

Installation

  1. Clone the repository
$ git clone [https://github.com/EmanElbedwihy/OMS.git]
  1. Create a .env file with the following database url
DATABASE_URL="postgresql://username:password@localhost:port/OMS?schema=public"

Replace 'username', 'password', and 'port' with your respective variables.

  1. Install npm packages
$ npm install
  1. Create the database
$ npx prisma generate
$ npx prisma migrate dev

Running

  1. Run the seeds and open prisma studio(for database display)
$ npm run seed
$ npx prisma studio
  1. Run the app
# development
$ npm run start

# watch mode
$ npm run start:dev
  1. Test the app

    The app can be tested using postman or thunder client through sending requests.

    Use swagger documentation for more details about APIs

http://localhost:3000/api

📃 Swagger Documentation

Swagger