From 61a0d62018af8ce9136e0a08419f90843280b0ea Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Fri, 20 Nov 2020 01:19:00 +0300 Subject: [PATCH] Fix for cyrillic letters in vin --- data_providers/vin01.js | 3 ++- models/vehicle.js | 9 +++++---- utils.js | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/data_providers/vin01.js b/data_providers/vin01.js index 9145506..f6b8e43 100644 --- a/data_providers/vin01.js +++ b/data_providers/vin01.js @@ -1,5 +1,6 @@ const fetch = require('node-fetch'); const Vehicle = require('../models/vehicle'); +const Utils = require('../utils'); const baseUrl = 'https://vin01.ru/v2'; const reportBaseUrl = `${baseUrl}/gibddApp.php`; @@ -62,7 +63,7 @@ class Vin01Provider { console.log('Vin01 base error: ', base.reason); console.log('Vin01 history error: ', history.reason); let vehicle = new Vehicle(); - vehicle.vin1 = vin; + vehicle.vin1 = Utils.cyrillicToLatin(vin); return vehicle; } else if(base.status == 'rejected') { console.log('vin01 found history'); diff --git a/models/vehicle.js b/models/vehicle.js index de185cc..46a2b77 100644 --- a/models/vehicle.js +++ b/models/vehicle.js @@ -1,4 +1,5 @@ const Constants = require('../data_providers/constants'); +const Utils = require('../utils'); class Vehicle { brand @@ -76,8 +77,8 @@ class Vehicle { volume: parseInt(main.engineVolume) }; v.year = parseInt(main.year, 10); - v.vin1 = main.vin; - v.vin2 = main.bodyNumber; + v.vin1 = Utils.cyrillicToLatin(main.vin); + v.vin2 = Utils.cyrillicToLatin(main.bodyNumber); v.color = main.color; v.ownershipPeriods = report.RequestResult.ownershipPeriods.ownershipPeriod.map(p => { @@ -107,8 +108,8 @@ class Vehicle { v.model = { normalized: first.model }; v.category = first.ts_category; v.year = parseInt(first.year); - v.vin1 = first.vin; - v.vin2 = first.body; + v.vin1 = Utils.cyrillicToLatin(first.vin); + v.vin2 = Utils.cyrillicToLatin(first.body); v.engine = { powerHp: parseFloat(first.engine_power), diff --git a/utils.js b/utils.js index 15f7a53..68013be 100644 --- a/utils.js +++ b/utils.js @@ -59,6 +59,12 @@ class Utils { 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; \ No newline at end of file