Web Lab Exam Final G4

Duration: 2 Hours
Total Marks: 50 (Lab Final)

Allowed Resources:

  • Internet
  • ChatGPT / AI tools
  • Official documentation
  • Personal term-project Git repository

Important Instructions

  1. Use your existing e-commerce term project.
  2. Create a new folder in your repository named:
lab-final-b
  1. All new code and changes must be inside this folder only.
  2. You must commit and push your work before the exam ends.
  3. You will be evaluated on:
    • Working features
    • Code quality
    • Git commits
    • Viva explanation

Scenario

Your current e-commerce application supports:

  • Product listing
  • Product details
  • Add to Cart (session-based)

The system is built using:

  • Express.js
  • MongoDB (Mongoose)
  • EJS

You are required to extend the system for post-cart and admin operations.


Task 1: Order Preview & Finalize Order

Objective

Introduce an Order Preview step before placing an order.

Requirements

  • Create a route /order/preview
  • Display:
    • Cart items
    • Individual prices
    • Quantity
    • Grand total
  • Provide two buttons:
    • Confirm Order
    • Go Back to Cart
  • On Confirm Order:
    • Save order in MongoDB
    • Order status must be Placed
    • Clear cart session
    • Redirect to success page with order summary

Task 2: Coupon / Discount Middleware

Objective

Apply discounts using middleware-based logic.

Requirements

  • Create middleware applyDiscount
  • If coupon code SAVE10 is passed as query or form input:
    • Apply 10% discount on total
  • Discount logic must:
    • Run before order is saved
    • Be reusable
  • Show discounted total on preview page

Task 3: Customer Order History

Objective

Allow customers to view their orders.

Requirements

  • Route: /my-orders
  • Ask user to enter email address
  • Display all orders placed using that email
  • Show:
    • Order ID
    • Date
    • Total
    • Status

Task 4: Order Status Lifecycle

Objective

Add multiple order states.

Requirements

  • Extend order statuses:
    • Placed
    • Processing
    • Delivered
  • Admin routes to:
    • Update order status step-by-step
    • Prevent skipping states (e.g., cannot go from Placed → Delivered)