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);
|
let report = await tgProvider.getReport(number);
|
||||||
await tgProvider.close();
|
await tgProvider.close();
|
||||||
|
|
||||||
if(!report.generalInfo && !report.insurance) {
|
if(!report?.generalInfo && !report?.insurance) {
|
||||||
res.send(makeError('No data found'));
|
res.send(makeError('No data found'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ router.post('/checkGbTg', async (req, res) => {
|
|||||||
if(vehicle) {
|
if(vehicle) {
|
||||||
let vinRegex = RegExp(vehicle.vin1.replace(/\*/g, '.'));
|
let vinRegex = RegExp(vehicle.vin1.replace(/\*/g, '.'));
|
||||||
|
|
||||||
if(report.generalInfo.vin.match(vinRegex)) {
|
if(report?.generalInfo?.vin?.match(vinRegex)) {
|
||||||
let updatedFields = {
|
let updatedFields = {
|
||||||
vin1: report.generalInfo.vin,
|
vin1: report.generalInfo.vin,
|
||||||
color: report.generalInfo.color,
|
color: report.generalInfo.color,
|
||||||
@ -315,12 +315,10 @@ router.post('/checkGbTg', async (req, res) => {
|
|||||||
updatedDate: Date.now()
|
updatedDate: Date.now()
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('insurance: ', report.insurance);
|
|
||||||
if(report.insurance) {
|
if(report.insurance) {
|
||||||
let osagoFound = vehicle.osagoContracts?.some(elem => {
|
let osagoFound = vehicle.osagoContracts?.some(elem => {
|
||||||
return elem.number = report.insurance.number;
|
return elem.number = report.insurance.number;
|
||||||
}) ?? false;
|
}) ?? false;
|
||||||
console.log('osago found: ', osagoFound);
|
|
||||||
if(!osagoFound) {
|
if(!osagoFound) {
|
||||||
await collection.updateOne({ number }, { $push: { osagoContracts: report.insurance } });
|
await collection.updateOne({ number }, { $push: { osagoContracts: report.insurance } });
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user