Fix for cyrillic letters in vin
This commit is contained in:
parent
d5fbe32933
commit
61a0d62018
@ -1,5 +1,6 @@
|
|||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const Vehicle = require('../models/vehicle');
|
const Vehicle = require('../models/vehicle');
|
||||||
|
const Utils = require('../utils');
|
||||||
|
|
||||||
const baseUrl = 'https://vin01.ru/v2';
|
const baseUrl = 'https://vin01.ru/v2';
|
||||||
const reportBaseUrl = `${baseUrl}/gibddApp.php`;
|
const reportBaseUrl = `${baseUrl}/gibddApp.php`;
|
||||||
@ -62,7 +63,7 @@ class Vin01Provider {
|
|||||||
console.log('Vin01 base error: ', base.reason);
|
console.log('Vin01 base error: ', base.reason);
|
||||||
console.log('Vin01 history error: ', history.reason);
|
console.log('Vin01 history error: ', history.reason);
|
||||||
let vehicle = new Vehicle();
|
let vehicle = new Vehicle();
|
||||||
vehicle.vin1 = vin;
|
vehicle.vin1 = Utils.cyrillicToLatin(vin);
|
||||||
return vehicle;
|
return vehicle;
|
||||||
} else if(base.status == 'rejected') {
|
} else if(base.status == 'rejected') {
|
||||||
console.log('vin01 found history');
|
console.log('vin01 found history');
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const Constants = require('../data_providers/constants');
|
const Constants = require('../data_providers/constants');
|
||||||
|
const Utils = require('../utils');
|
||||||
|
|
||||||
class Vehicle {
|
class Vehicle {
|
||||||
brand
|
brand
|
||||||
@ -76,8 +77,8 @@ class Vehicle {
|
|||||||
volume: parseInt(main.engineVolume)
|
volume: parseInt(main.engineVolume)
|
||||||
};
|
};
|
||||||
v.year = parseInt(main.year, 10);
|
v.year = parseInt(main.year, 10);
|
||||||
v.vin1 = main.vin;
|
v.vin1 = Utils.cyrillicToLatin(main.vin);
|
||||||
v.vin2 = main.bodyNumber;
|
v.vin2 = Utils.cyrillicToLatin(main.bodyNumber);
|
||||||
v.color = main.color;
|
v.color = main.color;
|
||||||
|
|
||||||
v.ownershipPeriods = report.RequestResult.ownershipPeriods.ownershipPeriod.map(p => {
|
v.ownershipPeriods = report.RequestResult.ownershipPeriods.ownershipPeriod.map(p => {
|
||||||
@ -107,8 +108,8 @@ class Vehicle {
|
|||||||
v.model = { normalized: first.model };
|
v.model = { normalized: first.model };
|
||||||
v.category = first.ts_category;
|
v.category = first.ts_category;
|
||||||
v.year = parseInt(first.year);
|
v.year = parseInt(first.year);
|
||||||
v.vin1 = first.vin;
|
v.vin1 = Utils.cyrillicToLatin(first.vin);
|
||||||
v.vin2 = first.body;
|
v.vin2 = Utils.cyrillicToLatin(first.body);
|
||||||
|
|
||||||
v.engine = {
|
v.engine = {
|
||||||
powerHp: parseFloat(first.engine_power),
|
powerHp: parseFloat(first.engine_power),
|
||||||
|
|||||||
6
utils.js
6
utils.js
@ -59,6 +59,12 @@ class Utils {
|
|||||||
|
|
||||||
return { $and: conditions };
|
return { $and: conditions };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cyrillicToLatin(str) {
|
||||||
|
const cyrillic_to_latin = { 'А': 'A', 'В': 'B', 'Е': 'E', 'К': 'K', 'М': 'M', 'Н': 'H', 'О': 'O', 'Р': 'P', 'С': 'C', 'Т': 'T', 'У': 'Y', 'Х': 'X' }; //{'А':'A', 'К':'K', 'М':'M', 'В':'B', 'С':'C'};
|
||||||
|
let regex = new RegExp('[' + Object.keys(cyrillic_to_latin).join('') + ']', 'g');
|
||||||
|
return str.replace(regex, letter => cyrillic_to_latin[letter] || letter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Utils;
|
module.exports = Utils;
|
||||||
Loading…
Reference in New Issue
Block a user