diff --git a/routes/vehicles.js b/routes/vehicles.js index 6302a48..b714831 100644 --- a/routes/vehicles.js +++ b/routes/vehicles.js @@ -296,7 +296,7 @@ router.post('/checkGbTg', async (req, res) => { let report = await tgProvider.getReport(number); await tgProvider.close(); - if(!report.generalInfo && !report.insurance) { + if(!report?.generalInfo && !report?.insurance) { res.send(makeError('No data found')); return; } @@ -307,7 +307,7 @@ router.post('/checkGbTg', async (req, res) => { if(vehicle) { let vinRegex = RegExp(vehicle.vin1.replace(/\*/g, '.')); - if(report.generalInfo.vin.match(vinRegex)) { + if(report?.generalInfo?.vin?.match(vinRegex)) { let updatedFields = { vin1: report.generalInfo.vin, color: report.generalInfo.color, @@ -315,12 +315,10 @@ router.post('/checkGbTg', async (req, res) => { updatedDate: Date.now() }; - console.log('insurance: ', report.insurance); if(report.insurance) { let osagoFound = vehicle.osagoContracts?.some(elem => { return elem.number = report.insurance.number; }) ?? false; - console.log('osago found: ', osagoFound); if(!osagoFound) { await collection.updateOne({ number }, { $push: { osagoContracts: report.insurance } }); }