debug: add comprehensive logging to vehicle import merge (refs #26)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m52s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 28s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m52s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 28s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
Added detailed logging to diagnose import merge issues: - Log vehicle count at merge start - Log each vehicle being processed with VIN/make/model/year - Log when existing vehicles are found (by VIN or license plate) - Log successful vehicle creation with new vehicle ID - Log errors with full context (userId, VIN, make, model, error message) - Log merge completion with summary statistics This will help diagnose why vehicles show as "successfully imported" but don't appear in the UI. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -231,6 +231,8 @@ export class UserImportService {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const vehicles = await this.archiveService.readDataFile<any>(extractedPath, 'vehicles.json');
|
const vehicles = await this.archiveService.readDataFile<any>(extractedPath, 'vehicles.json');
|
||||||
|
|
||||||
|
logger.info('Merge vehicles starting', { userId, vehicleCount: vehicles.length });
|
||||||
|
|
||||||
if (vehicles.length === 0) {
|
if (vehicles.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -242,11 +244,22 @@ export class UserImportService {
|
|||||||
|
|
||||||
for (const vehicle of chunk) {
|
for (const vehicle of chunk) {
|
||||||
try {
|
try {
|
||||||
|
logger.debug('Processing vehicle', {
|
||||||
|
userId,
|
||||||
|
vin: vehicle.vin,
|
||||||
|
make: vehicle.make,
|
||||||
|
model: vehicle.model,
|
||||||
|
year: vehicle.year,
|
||||||
|
});
|
||||||
|
|
||||||
let existing = null;
|
let existing = null;
|
||||||
|
|
||||||
// Try to find existing vehicle by VIN first
|
// Try to find existing vehicle by VIN first
|
||||||
if (vehicle.vin && vehicle.vin.trim().length > 0) {
|
if (vehicle.vin && vehicle.vin.trim().length > 0) {
|
||||||
existing = await this.vehiclesRepo.findByUserAndVIN(userId, vehicle.vin.trim());
|
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 VIN and license plate exists, try license plate
|
||||||
@@ -255,10 +268,17 @@ export class UserImportService {
|
|||||||
existing = allUserVehicles.find(
|
existing = allUserVehicles.find(
|
||||||
(v) => v.licensePlate && v.licensePlate.toLowerCase() === vehicle.licensePlate.toLowerCase()
|
(v) => v.licensePlate && v.licensePlate.toLowerCase() === vehicle.licensePlate.toLowerCase()
|
||||||
) || null;
|
) || null;
|
||||||
|
if (existing) {
|
||||||
|
logger.debug('Found existing vehicle by license plate', {
|
||||||
|
vehicleId: existing.id,
|
||||||
|
licensePlate: vehicle.licensePlate,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// Update existing vehicle
|
// Update existing vehicle
|
||||||
|
logger.debug('Updating existing vehicle', { vehicleId: existing.id });
|
||||||
await this.vehiclesRepo.update(existing.id, {
|
await this.vehiclesRepo.update(existing.id, {
|
||||||
make: vehicle.make,
|
make: vehicle.make,
|
||||||
model: vehicle.model,
|
model: vehicle.model,
|
||||||
@@ -278,7 +298,14 @@ export class UserImportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert new vehicle using service (enforces tier limits)
|
// Insert new vehicle using service (enforces tier limits)
|
||||||
await this.vehiclesService.createVehicle(
|
logger.debug('Creating new vehicle via service', {
|
||||||
|
userId,
|
||||||
|
vin: vehicle.vin || '',
|
||||||
|
make: vehicle.make,
|
||||||
|
model: vehicle.model,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.vehiclesService.createVehicle(
|
||||||
{
|
{
|
||||||
vin: vehicle.vin || '',
|
vin: vehicle.vin || '',
|
||||||
make: vehicle.make,
|
make: vehicle.make,
|
||||||
@@ -296,18 +323,34 @@ export class UserImportService {
|
|||||||
},
|
},
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.info('Vehicle created successfully', { vehicleId: result.id });
|
||||||
summary.imported++;
|
summary.imported++;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof VehicleLimitExceededError) {
|
const errorMsg =
|
||||||
summary.errors.push(
|
error instanceof VehicleLimitExceededError
|
||||||
`Vehicle limit exceeded: ${error.upgradePrompt} (current: ${error.currentCount}/${error.limit})`
|
? `Vehicle limit exceeded: ${error.upgradePrompt} (current: ${error.currentCount}/${error.limit})`
|
||||||
);
|
: `Vehicle import failed: ${error instanceof Error ? error.message : String(error)}`;
|
||||||
} else {
|
|
||||||
summary.errors.push(`Vehicle import failed: ${error instanceof Error ? error.message : String(error)}`);
|
logger.error('Vehicle import error', {
|
||||||
}
|
userId,
|
||||||
|
vin: vehicle.vin,
|
||||||
|
make: vehicle.make,
|
||||||
|
model: vehicle.model,
|
||||||
|
error: errorMsg,
|
||||||
|
});
|
||||||
|
|
||||||
|
summary.errors.push(errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info('Merge vehicles completed', {
|
||||||
|
userId,
|
||||||
|
imported: summary.imported,
|
||||||
|
updated: summary.updated,
|
||||||
|
errors: summary.errors.length,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user