kui-crm_actions 0.0.151 → 0.0.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -281,14 +281,14 @@ var inspectionsRequestBody = {
281
281
  getPartialInspectionMeters: function (meters) {
282
282
  var _this = this;
283
283
  return {
284
- meters: meters.map(function (meter, index) { return ({
284
+ meters: (meters === null || meters === void 0 ? void 0 : meters.map(function (meter, index) { return ({
285
285
  id: meter.id,
286
286
  resource_type: meter.resource,
287
287
  meter_type: meter.type,
288
288
  passport_number: meter.number,
289
289
  photos: _this.getFilesParams(meter.images),
290
290
  values: kuiUtils.clearNotValidFields(_this.getInspectionMeterValues(meter)),
291
- }); }),
291
+ }); })) || [],
292
292
  };
293
293
  },
294
294
  getPostBodyInventoryInspection: function (inspection, roomsImages, fillingFiles, metersFiles, contractFile) {
@@ -376,13 +376,42 @@ var inspectionsRequestBody = {
376
376
  });
377
377
  },
378
378
  getFilesParams: function (files) {
379
- return files
380
- .map(function (file) { return file.uploadedData; })
381
- .filter(function (data) { return data; });
379
+ return ((files === null || files === void 0 ? void 0 : files.map(function (file) { return file.uploadedData; }).filter(function (data) { return data; })) || []);
382
380
  },
383
381
  };
384
382
 
385
383
  var inspectionsRequests = {
384
+ createInspectionHandler: function (apartmentId, loader, callback) {
385
+ return __awaiter(this, void 0, void 0, function () {
386
+ var body, e_1, Sentry;
387
+ return __generator(this, function (_a) {
388
+ switch (_a.label) {
389
+ case 0:
390
+ if (!apartmentId) return [3 /*break*/, 5];
391
+ loader.startLoading("inspection creation");
392
+ body = void 0;
393
+ _a.label = 1;
394
+ case 1:
395
+ _a.trys.push([1, 3, , 4]);
396
+ return [4 /*yield*/, callback()];
397
+ case 2:
398
+ body = _a.sent();
399
+ return [3 /*break*/, 4];
400
+ case 3:
401
+ e_1 = _a.sent();
402
+ Sentry = kuiCrm.KUISettings.getSettings().Sentry;
403
+ Sentry.captureException(e_1);
404
+ loader.setError("inspection creation body", e_1);
405
+ return [3 /*break*/, 4];
406
+ case 4:
407
+ if (body)
408
+ return [2 /*return*/, this.createInspection(apartmentId, body, loader)];
409
+ return [2 /*return*/, null];
410
+ case 5: return [2 /*return*/, null];
411
+ }
412
+ });
413
+ });
414
+ },
386
415
  getInspectionTypes: function (apartmentId) {
387
416
  return __awaiter(this, void 0, void 0, function () {
388
417
  var _a, err, res;
@@ -430,83 +459,92 @@ var inspectionsRequests = {
430
459
  },
431
460
  createInitialInspection: function (data, apartmentId, loader) {
432
461
  return __awaiter(this, void 0, void 0, function () {
433
- var roomsImages, body;
462
+ var _this = this;
434
463
  return __generator(this, function (_a) {
435
- if (apartmentId) {
436
- loader.startLoading("inspection creation");
437
- roomsImages = this.getRoomParams(data.roomsImages);
438
- body = inspectionsRequestBody.getPostBodyInitialInspection(data, roomsImages);
439
- return [2 /*return*/, this.createInspection(apartmentId, body, loader)];
440
- }
441
- return [2 /*return*/, null];
464
+ return [2 /*return*/, this.createInspectionHandler(apartmentId, loader, function () { return __awaiter(_this, void 0, void 0, function () {
465
+ var roomsImages;
466
+ return __generator(this, function (_a) {
467
+ roomsImages = this.getRoomParams(data.roomsImages);
468
+ return [2 /*return*/, inspectionsRequestBody.getPostBodyInitialInspection(data, roomsImages)];
469
+ });
470
+ }); })];
442
471
  });
443
472
  });
444
473
  },
445
474
  createRegularInspection: function (data, apartmentId, loader) {
446
475
  return __awaiter(this, void 0, void 0, function () {
447
- var roomsImages, body;
476
+ var _this = this;
448
477
  return __generator(this, function (_a) {
449
- if (apartmentId) {
450
- loader.startLoading("inspection creation");
451
- roomsImages = this.getRoomParams(data.roomsImages);
452
- body = inspectionsRequestBody.getPostBodyRegularInspection(data, roomsImages);
453
- return [2 /*return*/, this.createInspection(apartmentId, body, loader)];
454
- }
455
- return [2 /*return*/, null];
478
+ return [2 /*return*/, this.createInspectionHandler(apartmentId, loader, function () { return __awaiter(_this, void 0, void 0, function () {
479
+ var roomsImages;
480
+ return __generator(this, function (_a) {
481
+ roomsImages = this.getRoomParams(data.roomsImages);
482
+ return [2 /*return*/, inspectionsRequestBody.getPostBodyRegularInspection(data, roomsImages)];
483
+ });
484
+ }); })];
456
485
  });
457
486
  });
458
487
  },
459
488
  createTransferInspection: function (data, apartmentId, loader) {
460
489
  return __awaiter(this, void 0, void 0, function () {
461
- var roomsImages, file, body;
490
+ var _this = this;
462
491
  return __generator(this, function (_a) {
463
- switch (_a.label) {
464
- case 0:
465
- if (!apartmentId) return [3 /*break*/, 2];
466
- loader.startLoading("inspection creation");
467
- roomsImages = this.getRoomParams(data.roomsImages);
468
- return [4 /*yield*/, kuiCrm.uploadNewFile(loader, data.contractFile)];
469
- case 1:
470
- file = _a.sent();
471
- body = inspectionsRequestBody.getPostBodyTransferInspection(data, roomsImages, file);
472
- return [2 /*return*/, this.createInspection(apartmentId, body, loader)];
473
- case 2: return [2 /*return*/, null];
474
- }
492
+ return [2 /*return*/, this.createInspectionHandler(apartmentId, loader, function () { return __awaiter(_this, void 0, void 0, function () {
493
+ var roomsImages, file;
494
+ return __generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0:
497
+ roomsImages = this.getRoomParams(data.roomsImages);
498
+ return [4 /*yield*/, kuiCrm.uploadNewFile(loader, data.contractFile)];
499
+ case 1:
500
+ file = _a.sent();
501
+ return [2 /*return*/, inspectionsRequestBody.getPostBodyTransferInspection(data, roomsImages, file)];
502
+ }
503
+ });
504
+ }); })];
475
505
  });
476
506
  });
477
507
  },
478
508
  createInventoryInspection: function (data, apartmentId, loader) {
479
- var _a;
480
509
  return __awaiter(this, void 0, void 0, function () {
481
- var fillingFiles, metersFiles, files, roomsImages, body;
482
- return __generator(this, function (_b) {
483
- switch (_b.label) {
484
- case 0:
485
- if (!apartmentId) return [3 /*break*/, 2];
486
- loader.startLoading("inspection creation");
487
- fillingFiles = data.fillingList.map(function (filling) { return filling.instruction; });
488
- metersFiles = ((_a = data.meters) === null || _a === void 0 ? void 0 : _a.map(function (meter) { return meter.passportFile; })) || [];
489
- return [4 /*yield*/, kuiUtils.callPromises([
490
- kuiCrm.uploadFiles(loader, fillingFiles),
491
- kuiCrm.uploadFiles(loader, metersFiles),
492
- kuiCrm.uploadNewFile(loader, data.contractFile),
493
- ])];
494
- case 1:
495
- files = _b.sent();
496
- roomsImages = this.getRoomParams(data.roomsImages);
497
- body = inspectionsRequestBody.getPostBodyInventoryInspection(data, roomsImages, files[0], files[1], files[2]);
498
- return [2 /*return*/, this.createInspection(apartmentId, body, loader)];
499
- case 2: return [2 /*return*/, null];
500
- }
510
+ var _this = this;
511
+ return __generator(this, function (_a) {
512
+ return [2 /*return*/, this.createInspectionHandler(apartmentId, loader, function () { return __awaiter(_this, void 0, void 0, function () {
513
+ var fillingFiles, metersFiles, files, roomsImages;
514
+ var _a;
515
+ return __generator(this, function (_b) {
516
+ switch (_b.label) {
517
+ case 0:
518
+ fillingFiles = data.fillingList.map(function (filling) { return filling.instruction; });
519
+ metersFiles = ((_a = data.meters) === null || _a === void 0 ? void 0 : _a.map(function (meter) { return meter.passportFile; })) || [];
520
+ return [4 /*yield*/, kuiUtils.callPromises([
521
+ kuiCrm.uploadFiles(loader, fillingFiles),
522
+ kuiCrm.uploadFiles(loader, metersFiles),
523
+ kuiCrm.uploadNewFile(loader, data.contractFile),
524
+ ])];
525
+ case 1:
526
+ files = _b.sent();
527
+ roomsImages = this.getRoomParams(data.roomsImages);
528
+ return [2 /*return*/, inspectionsRequestBody.getPostBodyInventoryInspection(data, roomsImages, files[0], files[1], files[2])];
529
+ }
530
+ });
531
+ }); })];
501
532
  });
502
533
  });
503
534
  },
504
535
  getRoomParams: function (rooms) {
505
- return rooms.map(function (room) { return ({
506
- purpose: room.type,
507
- comment: room.comment,
508
- photos: inspectionsRequestBody.getFilesParams(room.files),
509
- }); });
536
+ var roomIndex = -1;
537
+ return ((rooms === null || rooms === void 0 ? void 0 : rooms.map(function (room) {
538
+ var withOrderNumber = room.type === "room" || room.type === "bedroom";
539
+ if (withOrderNumber)
540
+ roomIndex += 1;
541
+ return {
542
+ purpose: room === null || room === void 0 ? void 0 : room.type,
543
+ comment: room === null || room === void 0 ? void 0 : room.comment,
544
+ photos: inspectionsRequestBody.getFilesParams(room.files),
545
+ room_order_number: withOrderNumber ? roomIndex : undefined,
546
+ };
547
+ })) || []);
510
548
  },
511
549
  };
512
550