Checking registration history as part of GB check
This commit is contained in:
parent
a1cfc3fb9a
commit
e31b0da001
@ -1,5 +1,6 @@
|
||||
import { TGClient } from './tgclient.js';
|
||||
import Utils from '../utils/utils.js';
|
||||
import Vin01Provider from './vin01.js';
|
||||
|
||||
class TGProvider {
|
||||
|
||||
@ -43,7 +44,7 @@ class TGProvider {
|
||||
await this.tgClient.close();
|
||||
}
|
||||
|
||||
async getReport(number) {
|
||||
async getReport(number, vin01token) {
|
||||
try {
|
||||
let waitResponseTask = Utils.promiseWithResolvers();
|
||||
this.checksMap.set(number, waitResponseTask);
|
||||
@ -53,7 +54,17 @@ class TGProvider {
|
||||
}, 25000);
|
||||
let { id, text } = await waitResponseTask.promise;
|
||||
await this.tgClient.viewMessage(id, this.chat.id);
|
||||
return this.parseReport(text);
|
||||
let report = this.parseReport(text);
|
||||
|
||||
if(vin01token && report.generalInfo.vin) {
|
||||
console.log('Found vin: ', report.generalInfo.vin);
|
||||
let vin01report = await Vin01Provider.getReportVin(report.generalInfo.vin, null, vin01token);
|
||||
if(vin01report.ownershipPeriods?.length > 0) {
|
||||
report.ownershipPeriods = vin01report.ownershipPeriods;
|
||||
}
|
||||
}
|
||||
|
||||
return report;
|
||||
} finally {
|
||||
this.checksMap.delete(number);
|
||||
}
|
||||
|
||||
@ -75,7 +75,18 @@ class Vin01Provider {
|
||||
try {
|
||||
let vin = await Vin01Provider.getVin(number, token);
|
||||
console.log('vin01 found VIN: ', vin);
|
||||
return await this.getReportVin(vin, number, token);
|
||||
} catch(ex) {
|
||||
ex.debugInfo = {
|
||||
vin01vin:DebugInfo.fromError(ex.message),
|
||||
vin01history: DebugInfo.fromError('Not applicable (VIN was not found)'),
|
||||
vin01base: DebugInfo.fromError('Not applicable (VIN was not found)')
|
||||
};
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
static async getReportVin(vin, number, token) {
|
||||
let checks = [Vin01Provider.runCheck('base', vin, token), Vin01Provider.runCheck('history', vin, token)];
|
||||
let [base, history] = (await Promise.allSettled(checks)).map(Vin01Provider.checkErrors);
|
||||
if(base.status == 'rejected' && history.status == 'rejected') {
|
||||
@ -146,14 +157,6 @@ class Vin01Provider {
|
||||
historyVehicle.number = number;
|
||||
return historyVehicle;
|
||||
}
|
||||
} catch(ex) {
|
||||
ex.debugInfo = {
|
||||
vin01vin:DebugInfo.fromError(ex.message),
|
||||
vin01history: DebugInfo.fromError('Not applicable (VIN was not found)'),
|
||||
vin01base: DebugInfo.fromError('Not applicable (VIN was not found)')
|
||||
};
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -290,10 +290,11 @@ router.post('/checkGbTg', async (req, res) => {
|
||||
|
||||
try {
|
||||
const number = req.body.number.replace(/ /g, '').toUpperCase();
|
||||
const token = req.body.token;
|
||||
|
||||
tgProvider = new TGProvider();
|
||||
await tgProvider.init();
|
||||
let report = await tgProvider.getReport(number);
|
||||
let report = await tgProvider.getReport(number, token);
|
||||
await tgProvider.close();
|
||||
|
||||
if(!report?.generalInfo && !report?.insurance) {
|
||||
@ -324,6 +325,10 @@ router.post('/checkGbTg', async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
if(report.ownershipPeriods) {
|
||||
updatedFields.ownershipPeriods = report.ownershipPeriods;
|
||||
}
|
||||
|
||||
await collection.updateOne({ number }, { $set: updatedFields });
|
||||
vehicle = await collection.findOne({ number });
|
||||
res.send({ success: true, data: Object.assign(vehicle, updatedFields) });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user