Skip to content

Abhrankan-Chakrabarti/Internship_caseStudies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Winternship 2025 Case Studies – Solutions

Welcome to my repository of solved lessons from the Winternship 2025 Case Studies.
This repo showcases my progress in mastering modern web development concepts through practical, hands-on challenges across TypeScript, React (Vite), MongoDB, and now Express.


📘 Overview

The Winternship 2025 program provides structured case studies across:

  • TypeScript → mastering language fundamentals, advanced types, generics, and design patterns
  • React (Vite) → building interactive UIs with hooks, state management, and component-driven architecture
  • MongoDB → designing aggregation pipelines for analytics and data transformation, CRUD operations, and ACID-compliant transactions
  • Express → backend routing, middleware, and REST APIs

Each case study bridges theory and practice with real-world coding exercises.


🚀 What’s Inside

  • CaseStudy1 (TypeScript)

    • Functions (optional, default, rest parameters, callbacks, recursion, overloads)
    • Advanced Types (union, utility, mapped types)
    • Generics (generic classes and functions)
    • Design Patterns (Observer, Strategy)
    • Classes & Access Modifiers (inheritance, private/protected members)
  • react/

    • Vite-based React app (my-react-app)

      • Component-driven solutions with hooks
      • State management patterns
      • Code-splitting and optimization
      • 🌐 Live Demo
    • Vite-based React app (my-task-app)

      • Standalone mini-app built with React + TypeScript
      • Interactive Task Manager (add, toggle, delete tasks with useReducer)
      • 🌐 Live Demo
  • mongodb/

    • Case Study 1: MovieFlix Analytics (solution.js)

      • Aggregation pipelines using $match, $group, $project, $sort, $limit
      • Example queries: views, ratings, genres
      • Runnable via mongosh or Node.js driver
    • Case Study 2: FastBite CRUD Challenge (menu-crud.js)

      • Demonstrates insertOne, find, updateOne, deleteOne
      • Idempotent script using upsert and $addToSet for repeatable runs
      • Runnable via mongosh or Node.js driver
    • Case Study 3: FinTrust Transactions & Refunds (refund-transaction.js, seed-refund.js)

      • Implements multi-document ACID transactions in MongoDB
      • Secure money transfers with replica set enabled
      • Refund workflow: balance adjustments, transaction status updates, and audit trail logging
      • Prints balances before and after refund for verification
      • Demonstrates rollback prevention and double-refund safeguards
  • express/

    • Lesson 1: Getting Started (app.js)
      • Basic Express server setup with npm init and npm install express
      • Routes: / (homepage), /events (list of activities), /contact (JSON with email + phone)
      • Demonstrates res.send() vs res.json() responses
      • Runnable via node app.js
    • Lesson 2: Modular routes (app.js, routes/)
      • Split routes into routes/events.js, routes/classes.js, routes/contact.js
      • Mounted routers in app.js with app.use('/path', router)
      • Organized project for scalability and team collaboration
      • Runnable via node app.js
    • Lesson 3: PATCH endpoint + validation (app.js, routes/products.js)
      • Implements PATCH /products/:id/inStock to update only the inStock field
      • Validates input: returns 400 Bad Request if inStock is missing or not a boolean
      • Returns 404 Not Found if product ID does not exist
      • Demonstrates partial updates, clear status codes, and modular routing
      • Runnable via node app.js
    • Lesson 4: POST /transfer endpoint (app.js, routes/transfer.js)
      • Implements POST /transfer to move points between accounts
      • Uses fixed valid UUIDs for Alice and Bob to simplify testing
      • Validates: both IDs must be valid UUIDs, points must be a positive integer
      • Returns 404 Not Found if sender/receiver not found, 400 Bad Request if invalid UUIDs or insufficient points
      • Responds with 200 OK and updated balances on success
      • Demonstrates transaction-like workflow, input validation, and structured error handling
      • Runnable via node app.js
    • Lesson 5: BakingController (app.js, routes/baking.js)
      • Implements POST /baking/start to begin baking an order
      • Implements GET /baking/status/:id to check baking status by order ID
      • Uses in-memory array to track baking orders
      • Validates: returns 400 Bad Request if orderId or flavor missing, 404 Not Found if order not found
      • Responds with 201 Created on start and 200 OK on status retrieval
      • Demonstrates modular routing, workflow separation, and clear status codes
      • Runnable via node app.js
    • Lesson 6: Discharge workflow with insurance middleware (app.js, routes/discharge.js)
      • Implements middleware chain for discharge: request log, doctor sign-off, pharmacy review, follow-up scheduling
      • Adds insuranceApprovalCheck middleware to enforce req.body.insuranceApproved
      • Returns 403 Forbidden when insurance approval is missing
      • Centralized error handler logs discharge steps for troubleshooting
      • Runnable via node app.js
    • Lesson 7: Admissions validation for art applicants (app.js, routes/applications.js)
      • Implements POST /applications endpoint to submit applications
      • Validates basic fields: applicant name and email required
      • Adds rule: if applicantType is "art", portfolioLink must be a valid URL
      • Returns 400 Bad Request with message "A valid portfolio link is required for art applicants." if missing or invalid
      • Responds with 201 Created and application payload on success
      • Demonstrates extending validation rules with clear, actionable feedback
      • Runnable via node app.js
    • Lesson 8: ReturnBook workflow with MVC (app.js, models/Book.js, repositories/, services/BookService.js, controllers/BookController.js)
      • Implements MVC pattern with clear separation of concerns
      • BookService enforces business rules for borrowing and returning books
      • BookController exposes endpoints:
        • POST /books/:id/borrow → borrow a book
        • POST /books/:id/return → return a book
      • Repository updates book status (isBorrowed flag) when returned
      • Demonstrates repository pattern and dependency injection for modular, testable code
      • Runnable via node app.js
    • Lesson 9: Course deletion workflow (app.js, models/Course.js, repositories/, services/CourseService.js, controllers/CourseController.js)
      • Implements delete(courseId) method in repository to remove courses from storage
      • CourseService adds deleteCourse method to enforce rules (course must exist before deletion)
      • CourseController exposes DELETE /courses/:id endpoint for admins
      • Returns 200 OK with success message or 404 Not Found if course does not exist
      • Demonstrates repository pattern, service layer enforcement, and controller routing for admin actions
      • Runnable via node app.js
    • Lesson 10: BillingService integration (app.js, services/, controllers/AppointmentController.js, tests/AppointmentService.test.js)
      • Defines BillingService interface and StripeBillingService implementation
      • AppointmentService injects both NotificationService and BillingService
      • bookAppointment charges patient and sends notification when booking
      • AppointmentController exposes POST /appointments/book endpoint
      • Unit test uses a mock billing service to verify charges are recorded
      • Demonstrates dependency injection, modular service design, and testability in Express
      • Runnable via node app.js

🛠️ How to Run

Clone the repository and run any case study as described below.

TypeScript (General Case Studies)

Most lessons can be run directly by compiling the TypeScript file and executing the generated JavaScript:

cd Internship_caseStudies/CaseStudy1
tsc lesson-name.ts
node lesson-name.js

TypeScript (Lesson 19)

Lesson 19 is a standalone TypeScript project and uses external dependencies.

cd Internship_caseStudies/CaseStudy1/nineteen
npm install
tsc
node dist/index.js

This will install required dependencies (typedi, reflect-metadata), compile the project using the local tsconfig.json, and run the output from the dist directory.

React (Vite)

cd Internship_caseStudies/react/my-react-app
npm install
npm run dev

This will start the Vite dev server and open the app in your browser.

Task Manager (Vite)

cd Internship_caseStudies/react/my-task-app
npm install
npm run dev

This will start the Vite dev server and open the app in your browser.
You can then interact with the Task Manager mini-app: add tasks, toggle completion, and delete tasks.

MongoDB

Case Study 1: MovieFlix Analytics

cd Internship_caseStudies/mongodb
npm install
node solution.js

Case Study 2: FastBite CRUD Challenge

cd Internship_caseStudies/mongodb
npm install
node menu-crud.js

Case Study 3: FinTrust Transactions & Refunds

cd Internship_caseStudies/mongodb
npm install
node seed-refund.js   # seed sample users + transaction
node refund-transaction.js   # run refund workflow

Express

Lesson 1: Getting Started

cd Internship_caseStudies/express/lesson1
npm install
node app.js

Then visit:

Lesson 2: Modular routes

cd Internship_caseStudies/express/lesson2
npm install
node app.js

Then visit:

Lesson 3: PATCH endpoint + validation

cd Internship_caseStudies/express/lesson3
npm install
node app.js

Then test:

# Valid update
curl -X PATCH http://localhost:3000/products/1/inStock \
  -H "Content-Type: application/json" \
  -d '{"inStock": false}'

# Invalid update (missing or wrong type)
curl -X PATCH http://localhost:3000/products/1/inStock \
  -H "Content-Type: application/json" \
  -d '{}'
curl -X PATCH http://localhost:3000/products/1/inStock \
  -H "Content-Type: application/json" \
  -d '{"inStock": "yes"}'

Lesson 4: POST /transfer endpoint

cd Internship_caseStudies/express/lesson4
npm install
node app.js

Then test:

# Valid transfer
curl -X POST http://localhost:3000/transfer \
  -H "Content-Type: application/json" \
  -d '{"fromCustomerId":"11111111-1111-4111-8111-111111111111","toCustomerId":"22222222-2222-4222-8222-222222222222","points":100}'

# Invalid UUIDs
curl -X POST http://localhost:3000/transfer \
  -H "Content-Type: application/json" \
  -d '{"fromCustomerId":"123","toCustomerId":"456","points":50}'

# Insufficient points
curl -X POST http://localhost:3000/transfer \
  -H "Content-Type: application/json" \
  -d '{"fromCustomerId":"22222222-2222-4222-8222-222222222222","toCustomerId":"11111111-1111-4111-8111-111111111111","points":9999}'

Lesson 5: BakingController

cd Internship_caseStudies/express/lesson5
npm install
node app.js

Then test:

# Start baking an order
curl -X POST http://localhost:3000/baking/start \
  -H "Content-Type: application/json" \
  -d '{"orderId":"101","flavor":"chocolate"}'

# Check baking status
curl -X GET http://localhost:3000/baking/status/101

Lesson 6: Discharge workflow with insurance middleware

cd Internship_caseStudies/express/lesson6
npm install
node app.js

Then test:

# Valid discharge request
curl -X POST http://localhost:3000/discharge \
  -H "Content-Type: application/json" \
  -d '{"patientName":"John Doe","doctorSigned":true,"pharmacyChecked":true,"followupScheduled":true,"insuranceApproved":true}'

# Missing insurance approval (should return 403)
curl -X POST http://localhost:3000/discharge \
  -H "Content-Type: application/json" \
  -d '{"patientName":"Jane Doe","doctorSigned":true,"pharmacyChecked":true,"followupScheduled":true}'

Lesson 7: Admissions validation for art applicants

cd Internship_caseStudies/express/lesson7
npm install
node app.js

Then test:

# Valid art applicant with portfolio link
curl -X POST http://localhost:3000/applications \
  -H "Content-Type: application/json" \
  -d '{"name":"Asha","email":"asha@example.com","applicantType":"art","portfolioLink":"https://asha-artfolio.com"}'

# Invalid: art applicant missing portfolioLink
curl -X POST http://localhost:3000/applications \
  -H "Content-Type: application/json" \
  -d '{"name":"Ravi","email":"ravi@example.com","applicantType":"art"}'

# Invalid: art applicant with malformed portfolioLink
curl -X POST http://localhost:3000/applications \
  -H "Content-Type: application/json" \
  -d '{"name":"Mira","email":"mira@example.com","applicantType":"art","portfolioLink":"not-a-url"}'

# Valid: non-art applicant (portfolio not required)
curl -X POST http://localhost:3000/applications \
  -H "Content-Type: application/json" \
  -d '{"name":"Karan","email":"karan@example.com","applicantType":"science"}'
  • ✅ Returns 201 Created with application payload if valid.
  • ❌ Returns 400 Bad Request with "A valid portfolio link is required for art applicants." if missing or invalid.
  • ✅ Non-art applicants pass without portfolioLink.

Lesson 8: ReturnBook workflow with MVC

cd Internship_caseStudies/express/lesson8
npm install
node app.js

Then test:

# Borrow a book
curl -X POST http://localhost:3000/books/1/borrow

# Return a book
curl -X POST http://localhost:3000/books/1/return

# Error: return a book that isn’t borrowed
curl -X POST http://localhost:3000/books/2/return
  • ✅ Borrow → JSON with isBorrowed: true
  • ✅ Return → JSON with isBorrowed: false
  • ❌ Error if book not found or invalid state

Lesson 9: Course deletion workflow

cd Internship_caseStudies/express/lesson9
npm install
node app.js

Then test:

# Delete an existing course
curl -X DELETE http://localhost:3000/courses/101

# Try deleting a non-existent course
curl -X DELETE http://localhost:3000/courses/999
  • ✅ Returns 200 OK with "Course deleted successfully" if found
  • ❌ Returns 404 Not Found with "Course not found" if missing

Lesson 10: BillingService integration

cd Internship_caseStudies/express/lesson10
npm install
node app.js

Then test:

# Book appointment with billing + notification
curl -X POST http://localhost:3000/appointments/book \
  -H "Content-Type: application/json" \
  -d '{"patient":"alice@example.com","time":"Monday 10am","amount":50}'

Expected:

  • ✅ Console logs: Stripe charge + SMS notification
  • ✅ Response JSON:
    {
      "status": "confirmed",
      "patient": "alice@example.com",
      "time": "Monday 10am",
      "amount": 50
    }

📈 Progress Tracker

  • TypeScript: Functions, Advanced Types, Generics, Design Patterns (Observer + Strategy), Classes & Access Modifiers
  • React (Vite): Component-driven solutions, hooks, state management
  • MongoDB Case Study 1: Aggregation pipeline (MovieFlix analytics)
  • MongoDB Case Study 2: CRUD challenge (FastBite menu, idempotent script)
  • MongoDB Case Study 3: Transactions & Refunds (FinTrust wallet, ACID compliance)
  • Express Lesson 1: Basic routes and server setup
  • Express Lesson 2: Modular routes with mounted routers
  • Express Lesson 3: PATCH endpoint with boolean validation
  • Express Lesson 4: POST /transfer endpoint with UUID validation and error handling
  • Express Lesson 5: BakingController
  • Express Lesson 6: Discharge workflow with insurance middleware
  • Express Lesson 7: Admissions validation for art applicants
  • Express Lesson 8: ReturnBook workflow with MVC pattern
  • Express Lesson 9: Course deletion workflow
  • Express Lesson 10: BillingService integration with AppointmentService

✨ Highlights

  • Strong focus on clarity and modularity.
  • Each solution includes conceptual explanation + runnable code.
  • Demonstrates growth across frontend, backend, and database layers of the MERN stack.
  • MongoDB scripts are idempotent and transaction-safe, ensuring repeatable outputs and ACID compliance.
  • Express lessons show step-by-step backend development, from simple routes to modular structure and precise REST endpoints with validation and middleware.

📜 License

This project is open-source under the MIT License.

About

Welcome to my repository of solved lessons from the Winternship 2025 Case Studies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors