From a1cfc3fb9a9fbafe70224b19044866a86b174187 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Mon, 1 Apr 2024 20:06:30 +0000 Subject: [PATCH] Fixed bug with parsing empty GB report --- routes/vehicles.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 } }); }