Fixed bug with parsing empty GB report
This commit is contained in:
parent
6117174f87
commit
a1cfc3fb9a
@ -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 } });
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user