tzi0

Untitled

Apr 18th, 2021 (edited)
635
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const allowRegion =
  2. {
  3.   AltaiKrai: 5,
  4.   AltaiRepublic: 5,
  5.   ZabaykalskyKrai: 2,
  6.   BelgorodOblast: 2,
  7.   Buryatia: 5,
  8.   KaliningradOblast: 4,
  9.   KemerovoOblast: 5,
  10.   KrasnoyarskKrai: 5,
  11.   OmskOblast: 5,
  12.   TulaOblast: 3,
  13.   Tuva: 5,
  14.   Khakassia: 5,
  15.   SamaraOblast: 5,
  16. };
  17.  
  18. //Данные которые приходят из формы
  19. const formDataUser =
  20. {
  21.   "attribute":
  22.   {
  23.     "id":null,
  24.     "IdAppeal":null,
  25.     "SendDate":null,
  26.     "p_ApplicationSendType":"57005",    
  27.     "_Status":null,
  28.     "ChangeDate":null,
  29.     "ApplicantType":"FL",
  30.     "Region":"SamaraOblast",
  31.     "Filial":"dzo_volga_samara_test",
  32.     "DZO":"dzo_volga",
  33.     "lastName":"Тест",
  34.     "firstName":"Тест",
  35.     "middleName":null,
  36.     "nameOrg":null,
  37.     "loginName":"96053988452",
  38.     "Login":null,
  39.     "contactphone":"0000002234",
  40.     "emailAddress":"cas@test.tt",
  41.     "InterestsUL":null,
  42.     "RedresentDoc":null,
  43.     "RedresentLastName":null,
  44.     "RedresentFirstName":null,
  45.     "RedresentMiddleName":null,
  46.     "RedresentDocType":null,
  47.     "RedresentDocNum":null,
  48.     "RedresentDocDate":null,
  49.     "deviceId":null,
  50.     "deviceSerialNumber":"3070",
  51.     "userAccount":"123456789",
  52.     "otkaz":null
  53.   },
  54.   "files":[]
  55. }
  56.  
  57.  
  58. //Ответ который приходит на проверку существования устройства по сн (может приходить несколько)
  59. const deviceList = {"value":[
  60. {"mrId":"e0f6aa26-9c96-42ac-9c0f-5bbb35e64464",
  61. "divisionId":5,"subdivisionId":0,"serialNumber":"3070","name":"РиМ 384",
  62. "setupDate":"2018-11-01T00:00:00.000Z","releaseDate":"2018-11-01T00:00:00.000Z",
  63. "trustDate":"1974-10-01T00:00:00.000Z","phaseCount":3,"timeZone":3,"description":"РиМ 384, №3070",
  64. "disconnect":0,"currentRating":100,"kWMultiplier":0,"kWhMultiplier":0,"transformerCTRatio":0,
  65. "transformerRatiosApplied":0,"transformerVTRatio":0,"voltageRating":10000,"modelVersion":"",
  66. "kh":0,"kr":0,"reverseFlowHandling":1,"serviceLocation":"a6f3b483-e031-4205-8fd4-9a89aaf216c3",
  67. "nsi":{"rootElement":{"valueKind":1}}},
  68.  
  69. {"mrId":"2677f38f-d602-41df-9dad-d5136c483f23","divisionId":27,"subdivisionId":0,"serialNumber":"3070",
  70. "name":"КАСКАД 200-МТ","setupDate":"2000-01-01T00:00:00.000Z","releaseDate":"2000-01-01T00:00:00.000Z",
  71. "trustDate":"1974-10-01T00:00:00.000Z","phaseCount":1,"timeZone":3,"description":"КАСКАД 200-МТ, №3070",
  72. "disconnect":0,"currentRating":0,"kWMultiplier":0,"kWhMultiplier":0,"transformerCTRatio":0,
  73. "transformerRatiosApplied":0,"transformerVTRatio":0,"voltageRating":0,"modelVersion":"","kh":0,"kr":0,
  74. "reverseFlowHandling":0,"serviceLocation":"fbaa30e8-ff90-40fb-b002-d75a4c1b5fb6","nsi":null},
  75.  
  76. {"mrId":"72769b70-7bc9-4eec-8e31-6ad15b442a58","divisionId":27,"subdivisionId":0,"serialNumber":"3070",
  77. "name":"КАСКАД 200-МТ","setupDate":"2000-01-01T00:00:00.000Z","releaseDate":"2000-01-01T00:00:00.000Z",
  78. "trustDate":"1974-10-01T00:00:00.000Z","phaseCount":1,"timeZone":3,"description":"КАСКАД 200-МТ, №3070",
  79. "disconnect":0,"currentRating":0,"kWMultiplier":0,"kWhMultiplier":0,"transformerCTRatio":0,
  80. "transformerRatiosApplied":0,"transformerVTRatio":0,"voltageRating":0,"modelVersion":"","kh":0,"kr":0,
  81. "reverseFlowHandling":0,"serviceLocation":"4ae1c3eb-0b58-43d2-86bc-690c5a2a062c","nsi":null}],
  82. "sysver":"0.0","status":200}
  83.  
  84.  
  85. function getDevice(regions, userData, devices) {  
  86.   const region = userData.attribute.Region;
  87.   if (region in regions) {
  88.     regionId = regions[region];
  89.     if (regionId) {
  90.       const _devices = devices.value.filter(device => device.divisionId == regionId);
  91.       return _devices.length > 0 ? _devices[0] : {} ;
  92.     }
  93.   } else return {};
  94. }
  95.  
  96. const devices = getDevice(allowRegion, formDataUser, deviceList);
  97. console.log(devices);
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×