hld
Class & Component Design
The code follows a strict 3-layer architecture to ensure separation of concerns.
src/controllers/):
SuccessResponse or ErrorResponse.FlightController.createFlight extracts body params and calls FlightService.src/services/):
FlightService.createFlight calls validateDateTime helper to ensure arrival > departure.FlightService.getAllFlights builds complex filters (price range, date, trip route).src/repositories/):
FlightRepository.getAllFlights uses Sequelize include to join Airplane, Airport, and City tables.FlightRepository.updateRemainingSeats manages DB transactions and locking.A. Flight Search (Dynamic Filtering)
Scenario: A user searches for flights from Mumbai (BOM) to Delhi (DEL) within a price range. The service builds a dynamic query.
The getAllFlights method supports dynamic filtering:
MUM-DEL -> splits into departureAirportId and arrivalAirportId.1000-5000 -> converts to Op.between.