Files
vip-coordinator/backend-old-20260125/dist/services/driverConflictService.js
kyle 868f7efc23
Some checks failed
CI/CD Pipeline / Backend Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Tests (push) Has been cancelled
CI/CD Pipeline / Build Docker Images (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
Major Enhancement: NestJS Migration + CASL Authorization + Error Handling
Complete rewrite from Express to NestJS with enterprise-grade features:

## Backend Improvements
- Migrated from Express to NestJS 11.0.1 with TypeScript
- Implemented Prisma ORM 7.3.0 for type-safe database access
- Added CASL authorization system replacing role-based guards
- Created global exception filters with structured logging
- Implemented Auth0 JWT authentication with Passport.js
- Added vehicle management with conflict detection
- Enhanced event scheduling with driver/vehicle assignment
- Comprehensive error handling and logging

## Frontend Improvements
- Upgraded to React 19.2.0 with Vite 7.2.4
- Implemented CASL-based permission system
- Added AbilityContext for declarative permissions
- Created ErrorHandler utility for consistent error messages
- Enhanced API client with request/response logging
- Added War Room (Command Center) dashboard
- Created VIP Schedule view with complete itineraries
- Implemented Vehicle Management UI
- Added mock data generators for testing (288 events across 20 VIPs)

## New Features
- Vehicle fleet management (types, capacity, status tracking)
- Complete 3-day Jamboree schedule generation
- Individual VIP schedule pages with PDF export (planned)
- Real-time War Room dashboard with auto-refresh
- Permission-based navigation filtering
- First user auto-approval as administrator

## Documentation
- Created CASL_AUTHORIZATION.md (comprehensive guide)
- Created ERROR_HANDLING.md (error handling patterns)
- Updated CLAUDE.md with new architecture
- Added migration guides and best practices

## Technical Debt Resolved
- Removed custom authentication in favor of Auth0
- Replaced role checks with CASL abilities
- Standardized error responses across API
- Implemented proper TypeScript typing
- Added comprehensive logging

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-31 08:50:25 +01:00

123 lines
5.4 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DriverConflictService {
// Check for conflicts when assigning a driver to an event
checkDriverConflicts(driverId, newEvent, allSchedules, drivers) {
const conflicts = [];
const driver = drivers.find(d => d.id === driverId);
if (!driver)
return conflicts;
// Get all events assigned to this driver
const driverEvents = this.getDriverEvents(driverId, allSchedules);
const newStartTime = new Date(newEvent.startTime);
const newEndTime = new Date(newEvent.endTime);
for (const existingEvent of driverEvents) {
const existingStart = new Date(existingEvent.startTime);
const existingEnd = new Date(existingEvent.endTime);
// Check for direct time overlap
if (this.hasTimeOverlap(newStartTime, newEndTime, existingStart, existingEnd)) {
conflicts.push({
type: 'overlap',
severity: 'high',
message: `Direct time conflict with "${existingEvent.title}" for ${existingEvent.vipName}`,
conflictingEvent: existingEvent
});
}
// Check for tight turnaround (less than 15 minutes between events)
else {
const timeBetween = this.getTimeBetweenEvents(newStartTime, newEndTime, existingStart, existingEnd);
if (timeBetween !== null && timeBetween < 15) {
conflicts.push({
type: 'tight_turnaround',
severity: timeBetween < 5 ? 'high' : 'medium',
message: `Only ${timeBetween} minutes between events. Previous: "${existingEvent.title}"`,
conflictingEvent: existingEvent,
timeDifference: timeBetween
});
}
}
}
return conflicts;
}
// Get availability status for all drivers for a specific time slot
getDriverAvailability(eventTime, allSchedules, drivers) {
return drivers.map(driver => {
const conflicts = this.checkDriverConflicts(driver.id, eventTime, allSchedules, drivers);
const driverEvents = this.getDriverEvents(driver.id, allSchedules);
let status = 'available';
if (conflicts.length > 0) {
const hasOverlap = conflicts.some(c => c.type === 'overlap');
const hasTightTurnaround = conflicts.some(c => c.type === 'tight_turnaround');
if (hasOverlap) {
status = 'overlapping';
}
else if (hasTightTurnaround) {
status = 'tight_turnaround';
}
}
else if (driverEvents.length > 0) {
status = 'scheduled';
}
return {
driverId: driver.id,
driverName: driver.name,
status,
assignmentCount: driverEvents.length,
conflicts,
currentAssignments: driverEvents
};
});
}
// Get all events assigned to a specific driver
getDriverEvents(driverId, allSchedules) {
const driverEvents = [];
Object.entries(allSchedules).forEach(([vipId, events]) => {
events.forEach(event => {
if (event.assignedDriverId === driverId) {
driverEvents.push({
...event,
vipId,
vipName: event.title // We'll need to get actual VIP name from VIP data
});
}
});
});
// Sort by start time
return driverEvents.sort((a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime());
}
// Check if two time periods overlap
hasTimeOverlap(start1, end1, start2, end2) {
return start1 < end2 && start2 < end1;
}
// Get minutes between two events (null if they overlap)
getTimeBetweenEvents(newStart, newEnd, existingStart, existingEnd) {
// If new event is after existing event
if (newStart >= existingEnd) {
return Math.floor((newStart.getTime() - existingEnd.getTime()) / (1000 * 60));
}
// If new event is before existing event
else if (newEnd <= existingStart) {
return Math.floor((existingStart.getTime() - newEnd.getTime()) / (1000 * 60));
}
// Events overlap
return null;
}
// Generate summary message for driver status
getDriverStatusSummary(availability) {
switch (availability.status) {
case 'available':
return `✅ Fully available (${availability.assignmentCount} assignments)`;
case 'scheduled':
return `🟡 Has ${availability.assignmentCount} assignment(s) but available for this time`;
case 'tight_turnaround':
const tightConflict = availability.conflicts.find(c => c.type === 'tight_turnaround');
return `⚡ Tight turnaround - ${tightConflict?.timeDifference} min between events`;
case 'overlapping':
return `🔴 Time conflict with existing assignment`;
default:
return 'Unknown status';
}
}
}
exports.default = new DriverConflictService();
//# sourceMappingURL=driverConflictService.js.map