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).
The System has the following APIs :
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). 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. 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. 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. This API fetches details of a specific order by its ID. It fails if the order is not found or if validation fails. 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). 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. 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. 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.This is a list of needed instructions to run the project locally
- Clone the repository
$ git clone [https://github.com/EmanElbedwihy/OMS.git]
- 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.
- Install npm packages
$ npm install
- Create the database
$ npx prisma generate
$ npx prisma migrate dev
- Run the seeds and open prisma studio(for database display)
$ npm run seed
$ npx prisma studio
- Run the app
# development
$ npm run start
# watch mode
$ npm run start:dev
- 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