Fixed bug with parsing empty GB report

This commit is contained in:
Selim Mustafaev 2024-04-01 20:06:30 +00:00
parent 6117174f87
commit a1cfc3fb9a

View File

@ -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 } });
}