feat: Add user data import feature (Fixes #26) #27

Merged
egullickson merged 11 commits from issue-26-add-user-data-import into main 2026-01-12 03:22:32 +00:00
Showing only changes of commit 28574b0eb4 - Show all commits

View File

@@ -246,23 +246,41 @@ export class UserImportService {
try {
logger.debug('Processing vehicle', {
userId,
id: vehicle.id,
vin: vehicle.vin,
make: vehicle.make,
model: vehicle.model,
year: vehicle.year,
licensePlate: vehicle.licensePlate,
});
let existing = null;
// Try to find existing vehicle by VIN first
if (vehicle.vin && vehicle.vin.trim().length > 0) {
// Try to find existing vehicle by ID first (preserves identity across exports)
if (vehicle.id) {
existing = await this.vehiclesRepo.findById(vehicle.id);
// Verify it belongs to the same user
if (existing && existing.userId !== userId) {
logger.warn('Vehicle ID belongs to different user, ignoring', {
vehicleId: vehicle.id,
expectedUserId: userId,
actualUserId: existing.userId,
});
existing = null;
} else if (existing) {
logger.debug('Found existing vehicle by ID', { vehicleId: existing.id });
}
}
// Try to find existing vehicle by VIN if not found by ID
if (!existing && vehicle.vin && vehicle.vin.trim().length > 0) {
existing = await this.vehiclesRepo.findByUserAndVIN(userId, vehicle.vin.trim());
if (existing) {
logger.debug('Found existing vehicle by VIN', { vehicleId: existing.id, vin: vehicle.vin });
}
}
// If not found by VIN and license plate exists, try license plate
// If not found by ID or VIN, and license plate exists, try license plate
if (!existing && vehicle.licensePlate && vehicle.licensePlate.trim().length > 0) {
const allUserVehicles = await this.vehiclesRepo.findByUserId(userId);
existing = allUserVehicles.find(