Duration: 2 Hours
Total Marks: 50 (Lab Final)
Allowed Resources:
- Internet
- ChatGPT / AI tools
- Official documentation
- Personal term-project repository
Important Instructions
- You will work on your existing e-commerce term project.
- Do NOT modify existing code directly.
- Create a new folder in your repository named:
lab-final
- All new or modified code must be placed inside this folder.
- You must:
- Commit your work with meaningful commit messages
- Push changes to your remote Git repository before time ends
- You will be assessed on:
- Working functionality
- Code quality
- Commit history
- Ability to explain your work during viva
Scenario
Your existing e-commerce system is built using:
- Node.js
- Express
- MongoDB (Mongoose)
- EJS
- Session-based cart
Currently, the system supports:
- Product listing
- Product details
- Add to Cart functionality
You are required to extend and improve the system without breaking existing features.
Task 1: Checkout & Order Creation
Objective
Convert the cart into a persistent order.
Requirements
- Create an Order model using Mongoose containing:
- Customer name
- Cart items (product, quantity, price)
- Total amount
- Order status (
Pending,Confirmed,Cancelled) - Created date
- Create a Checkout page:
- Shows cart items
- Shows total amount
- Takes customer name and email
- On order submission:
- Save order in MongoDB
- Clear cart session
- Redirect to an Order Confirmation page displaying the Order ID
Task 2: Middleware & Route Protection
Objective
Implement reusable middleware for validation and authorization.
Requirements
- Create middleware:
checkCartNotEmpty- Prevent checkout when cart is empty
adminOnly- Allow access only if email equals
admin@shop.com
- Allow access only if email equals
- Apply middleware properly to relevant routes
Task 3: Admin Orders Dashboard
Objective
Build a simple Admin Orders Panel.
Requirements
- Route:
/admin/orders - Display a list of all orders showing:
- Order ID
- Customer name
- Total amount
- Status
- Order date
- Add actions:
- Mark order as Confirmed
- Cancel order
- Status changes must update the database
Task 4: Data Integrity & Edge Cases
Objective
Improve reliability of the system.
Implement ANY TWO of the following:
- Prevent duplicate products in cart
- Recalculate cart total on the server
- Handle deleted products already present in cart
- Validate checkout form inputs (server-side)
Task 5: Code Understanding & Debugging
Objective
Demonstrate real understanding of your code.
Requirements
- Add meaningful comments explaining:
- One route
- One middleware
- Fix one existing issue in your project (example):
- Missing async error handling
- Incorrect cart total
- Session-related bug
- Be prepared to explain during viva:
- Why sessions are used for cart
- Why middleware is preferred over repeated logic
- Difference between
populate()and embedded documents - How orders differ from carts conceptually
Submission Requirements
- Code must exist only inside
lab-final/folder - Repository must be pushed before exam ends
- Application must run using:
npm install npm start
Academic Integrity Notice
- ChatGPT is allowed
- You must be able to explain your code
- Copy-paste without understanding will result in zero marks