taxtank-core 0.23.9 → 0.24.1

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.
@@ -586,13 +586,18 @@
586
586
  AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_CREATED"] = 37] = "TRANSACTION_CREATED";
587
587
  AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_DELETED"] = 38] = "TRANSACTION_DELETED";
588
588
  AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_UPDATED"] = 39] = "TRANSACTION_UPDATED";
589
- AppEventTypeEnum[AppEventTypeEnum["TRANSACTIONS_CREATED"] = 40] = "TRANSACTIONS_CREATED";
590
- AppEventTypeEnum[AppEventTypeEnum["USER_UPDATED"] = 41] = "USER_UPDATED";
591
- AppEventTypeEnum[AppEventTypeEnum["VEHICLE_CLAIM_UPDATED"] = 42] = "VEHICLE_CLAIM_UPDATED";
592
- AppEventTypeEnum[AppEventTypeEnum["VEHICLE_CLAIM_CREATED"] = 43] = "VEHICLE_CLAIM_CREATED";
593
- AppEventTypeEnum[AppEventTypeEnum["VEHICLE_LOGBOOK_CREATED"] = 44] = "VEHICLE_LOGBOOK_CREATED";
594
- AppEventTypeEnum[AppEventTypeEnum["VEHICLE_LOGBOOK_UPDATED"] = 45] = "VEHICLE_LOGBOOK_UPDATED";
595
- AppEventTypeEnum[AppEventTypeEnum["VEHICLE_LOGBOOK_DELETED"] = 46] = "VEHICLE_LOGBOOK_DELETED";
589
+ AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_CREATED_WITH_NEW_RECEIPT"] = 40] = "TRANSACTION_CREATED_WITH_NEW_RECEIPT";
590
+ AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_UPDATED_WITH_NEW_RECEIPT"] = 41] = "TRANSACTION_UPDATED_WITH_NEW_RECEIPT";
591
+ AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_UPDATED_WITH_DELETED_RECEIPT"] = 42] = "TRANSACTION_UPDATED_WITH_DELETED_RECEIPT";
592
+ AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_RECEIPT_CREATED"] = 43] = "TRANSACTION_RECEIPT_CREATED";
593
+ AppEventTypeEnum[AppEventTypeEnum["TRANSACTION_RECEIPT_DELETED"] = 44] = "TRANSACTION_RECEIPT_DELETED";
594
+ AppEventTypeEnum[AppEventTypeEnum["TRANSACTIONS_CREATED"] = 45] = "TRANSACTIONS_CREATED";
595
+ AppEventTypeEnum[AppEventTypeEnum["USER_UPDATED"] = 46] = "USER_UPDATED";
596
+ AppEventTypeEnum[AppEventTypeEnum["VEHICLE_CLAIM_UPDATED"] = 47] = "VEHICLE_CLAIM_UPDATED";
597
+ AppEventTypeEnum[AppEventTypeEnum["VEHICLE_CLAIM_CREATED"] = 48] = "VEHICLE_CLAIM_CREATED";
598
+ AppEventTypeEnum[AppEventTypeEnum["VEHICLE_LOGBOOK_CREATED"] = 49] = "VEHICLE_LOGBOOK_CREATED";
599
+ AppEventTypeEnum[AppEventTypeEnum["VEHICLE_LOGBOOK_UPDATED"] = 50] = "VEHICLE_LOGBOOK_UPDATED";
600
+ AppEventTypeEnum[AppEventTypeEnum["VEHICLE_LOGBOOK_DELETED"] = 51] = "VEHICLE_LOGBOOK_DELETED";
596
601
  })(exports.AppEventTypeEnum || (exports.AppEventTypeEnum = {}));
597
602
 
598
603
  var EventDispatcherService = /** @class */ (function () {
@@ -1056,6 +1061,8 @@
1056
1061
  TRANSACTIONS_ALLOCATIONS_GET: new Endpoint('GET', '\\/transactions-allocations'),
1057
1062
  TRANSACTIONS_ALLOCATIONS_POST: new Endpoint('POST', '\\/transactions-allocations'),
1058
1063
  TRANSACTIONS_ALLOCATIONS_DELETE: new Endpoint('DELETE', '\\/transactions-allocations\\/\\d+'),
1064
+ TRANSACTION_RECEIPTS_POST: new Endpoint('POST', '\\/transactions\\/\\d+\\/receipts'),
1065
+ TRANSACTION_RECEIPTS_DELETE: new Endpoint('DELETE', '\\/transactions\\/\\d+\\/receipts\\/\\d+'),
1059
1066
  USER_CONFIRMATION_POST: new Endpoint('POST', '\\/users\\/confirmation'),
1060
1067
  USER_CONFIRMATION_RESEND_POST: new Endpoint('POST', '\\/users\\/confirmation\\/resend'),
1061
1068
  USER_CURRENT_GET: new Endpoint('GET', '\\/users\\/current'),
@@ -2153,7 +2160,7 @@
2153
2160
  */
2154
2161
  get: function () {
2155
2162
  var isExpired = new Date(this.endDate).getTime() < new Date().getTime();
2156
- return isExpired && ([exports.ServiceSubscriptionStatusEnum.ACTIVE, exports.ServiceSubscriptionStatusEnum.PAST_DUE].includes(this.status));
2163
+ return !isExpired && ([exports.ServiceSubscriptionStatusEnum.ACTIVE, exports.ServiceSubscriptionStatusEnum.PAST_DUE].includes(this.status));
2157
2164
  },
2158
2165
  enumerable: false,
2159
2166
  configurable: true
@@ -11428,13 +11435,87 @@
11428
11435
  return list;
11429
11436
  }
11430
11437
 
11438
+ var TransactionReceiptService = /** @class */ (function () {
11439
+ function TransactionReceiptService(http, eventDispatcherService, environment) {
11440
+ this.http = http;
11441
+ this.eventDispatcherService = eventDispatcherService;
11442
+ this.environment = environment;
11443
+ this.url = 'receipts';
11444
+ this.listenEvents();
11445
+ }
11446
+ /**
11447
+ * Transaction instance is necessary to take the ID and the receipt file from it.
11448
+ */
11449
+ TransactionReceiptService.prototype.add = function (transaction) {
11450
+ var _this = this;
11451
+ var formData = new FormData();
11452
+ formData.append('file', transaction.file);
11453
+ this.http.post(this.environment.apiV2 + "/transactions/" + transaction.id + "/" + this.url, formData)
11454
+ .subscribe(function (receiptResponse) {
11455
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_RECEIPT_CREATED, classTransformer.plainToClass(TransactionReceipt, receiptResponse)));
11456
+ });
11457
+ };
11458
+ /**
11459
+ * Transaction instance is necessary to take the ID and the receipt ID from it.
11460
+ */
11461
+ TransactionReceiptService.prototype.delete = function (transaction) {
11462
+ var _this = this;
11463
+ this.http.delete(this.environment.apiV2 + "/transactions/" + transaction.id + "/" + this.url + "/" + transaction.receipt.id)
11464
+ .subscribe(function () {
11465
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_RECEIPT_DELETED, transaction));
11466
+ });
11467
+ };
11468
+ TransactionReceiptService.prototype.listenEvents = function () {
11469
+ this.listenTransactionWithReceiptUpdated();
11470
+ this.listenTransactionWithoutReceiptUpdated();
11471
+ };
11472
+ TransactionReceiptService.prototype.listenTransactionWithReceiptUpdated = function () {
11473
+ var _this = this;
11474
+ this.eventDispatcherService.on([
11475
+ exports.AppEventTypeEnum.TRANSACTION_CREATED_WITH_NEW_RECEIPT,
11476
+ exports.AppEventTypeEnum.TRANSACTION_UPDATED_WITH_NEW_RECEIPT
11477
+ ]).subscribe(function (transaction) {
11478
+ _this.add(transaction);
11479
+ });
11480
+ };
11481
+ /**
11482
+ * Case when transaction was updated, but receipt was removed
11483
+ */
11484
+ TransactionReceiptService.prototype.listenTransactionWithoutReceiptUpdated = function () {
11485
+ var _this = this;
11486
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.TRANSACTION_UPDATED_WITH_DELETED_RECEIPT)
11487
+ .subscribe(function (transaction) {
11488
+ _this.delete(transaction);
11489
+ });
11490
+ };
11491
+ return TransactionReceiptService;
11492
+ }());
11493
+ TransactionReceiptService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionReceiptService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11494
+ TransactionReceiptService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionReceiptService, providedIn: 'root' });
11495
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionReceiptService, decorators: [{
11496
+ type: i0.Injectable,
11497
+ args: [{
11498
+ providedIn: 'root'
11499
+ }]
11500
+ }], ctorParameters: function () {
11501
+ return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
11502
+ type: i0.Inject,
11503
+ args: ['environment']
11504
+ }] }];
11505
+ } });
11506
+
11431
11507
  /**
11432
11508
  * Service for transactions business logic
11433
11509
  */
11434
11510
  var TransactionService = /** @class */ (function (_super) {
11435
11511
  __extends(TransactionService, _super);
11436
- function TransactionService() {
11437
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11512
+ function TransactionService(http, eventDispatcherService, environment, toastService, transactionReceiptService) {
11513
+ var _this = _super.call(this, http, eventDispatcherService, environment, toastService) || this;
11514
+ _this.http = http;
11515
+ _this.eventDispatcherService = eventDispatcherService;
11516
+ _this.environment = environment;
11517
+ _this.toastService = toastService;
11518
+ _this.transactionReceiptService = transactionReceiptService;
11438
11519
  // url part for Transaction API
11439
11520
  _this.url = 'transactions';
11440
11521
  _this.modelClass = Transaction;
@@ -11447,6 +11528,8 @@
11447
11528
  TransactionService.prototype.listenEvents = function () {
11448
11529
  this.listenDepreciationChange();
11449
11530
  this.listenPropertyShareUpdate();
11531
+ this.listenReceiptAdded();
11532
+ this.listenReceiptDeleted();
11450
11533
  };
11451
11534
  /**
11452
11535
  * get list of all user's TaxTank transactions
@@ -11541,11 +11624,10 @@
11541
11624
  transactions.forEach(function (transaction, index) {
11542
11625
  // @TODO backend: need to upload file in the same backend endpoint with transaction add/update
11543
11626
  // check if passed receipt and upload file
11544
- // @TODO Alex: refactor. Move receipt to separated service and use event dispatcher to handle it
11545
11627
  if (transaction.file && (transaction.file instanceof File)) {
11546
11628
  transaction.id = response[index].id;
11547
11629
  addedTransactions[index].file = transaction.file;
11548
- _this.uploadReceipt(addedTransactions[index]);
11630
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_CREATED_WITH_NEW_RECEIPT, addedTransactions[index]));
11549
11631
  }
11550
11632
  // @TODO Viktor: implement API for saving of nested transactions
11551
11633
  // add child transactions if exist
@@ -11579,10 +11661,13 @@
11579
11661
  var updatedTransaction = classTransformer.plainToClass(Transaction, response);
11580
11662
  // @TODO need to upload file in the same backend endpoint with transaction add/update
11581
11663
  // check if passed new receipt and upload file
11582
- // @TODO Alex: refactor. Move receipt to separated service and use event dispatcher to handle it
11583
11664
  if (transaction.file && (transaction.file instanceof File)) {
11584
11665
  updatedTransaction.file = transaction.file;
11585
- _this.uploadReceipt(updatedTransaction);
11666
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_UPDATED_WITH_NEW_RECEIPT, updatedTransaction));
11667
+ // receipt file was removed from form - we should delete receipt from transaction
11668
+ }
11669
+ else if (!transaction.file && transaction.receipt) {
11670
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_UPDATED_WITH_DELETED_RECEIPT, updatedTransaction));
11586
11671
  }
11587
11672
  // @TODO Viktor: implement API for saving of nested transactions
11588
11673
  if (transaction.transactions.length) {
@@ -11654,24 +11739,6 @@
11654
11739
  _this.transactionDeleted.emit(model);
11655
11740
  }));
11656
11741
  };
11657
- /**
11658
- * upload transaction receipt image
11659
- * @param transaction Еhe transaction for which the receipt will be imported
11660
- */
11661
- TransactionService.prototype.uploadReceipt = function (transaction) {
11662
- var _this = this;
11663
- var formData = new FormData();
11664
- formData.append('file', transaction.file);
11665
- transaction.receipt = null;
11666
- this.http.post(this.environment.apiV2 + "/" + this.url + "/" + transaction.id + "/receipts", formData)
11667
- .subscribe(function (receiptResponse) {
11668
- // we don't need to keep file after save
11669
- transaction.file = null;
11670
- transaction.receipt = classTransformer.plainToClass(TransactionReceipt, receiptResponse);
11671
- replace(_this.cache, transaction);
11672
- _this.updateCache();
11673
- });
11674
- };
11675
11742
  /**
11676
11743
  * calculate gross income amount based on transaction amount and taxes (fees)
11677
11744
  * @param transaction Transaction instance for calculation
@@ -11733,16 +11800,41 @@
11733
11800
  var _this = this;
11734
11801
  this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED).subscribe(function () { return _this.resetCache(); });
11735
11802
  };
11803
+ TransactionService.prototype.listenReceiptAdded = function () {
11804
+ var _this = this;
11805
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.TRANSACTION_RECEIPT_CREATED).subscribe(function (transactionReceipt) {
11806
+ var transactionToUpdate = _this.find(transactionReceipt.transaction.id);
11807
+ // we don't need to keep file after save
11808
+ transactionToUpdate.file = null;
11809
+ transactionToUpdate.receipt = transactionReceipt;
11810
+ replace(_this.cache, transactionToUpdate);
11811
+ _this.updateCache();
11812
+ });
11813
+ };
11814
+ TransactionService.prototype.listenReceiptDeleted = function () {
11815
+ var _this = this;
11816
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.TRANSACTION_RECEIPT_DELETED).subscribe(function (transaction) {
11817
+ var transactionToUpdate = _this.find(transaction.id);
11818
+ transactionToUpdate.receipt = null;
11819
+ replace(_this.cache, transactionToUpdate);
11820
+ _this.updateCache();
11821
+ });
11822
+ };
11736
11823
  return TransactionService;
11737
11824
  }(RestService));
11738
- TransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11825
+ TransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }, { token: ToastService }, { token: TransactionReceiptService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11739
11826
  TransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, providedIn: 'root' });
11740
11827
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, decorators: [{
11741
11828
  type: i0.Injectable,
11742
11829
  args: [{
11743
11830
  providedIn: 'root'
11744
11831
  }]
11745
- }] });
11832
+ }], ctorParameters: function () {
11833
+ return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
11834
+ type: i0.Inject,
11835
+ args: ['environment']
11836
+ }] }, { type: ToastService }, { type: TransactionReceiptService }];
11837
+ } });
11746
11838
 
11747
11839
  /**
11748
11840
  * Service handling user's account setup process.
@@ -15262,6 +15354,28 @@
15262
15354
  }]
15263
15355
  }] });
15264
15356
 
15357
+ /**
15358
+ * Service to work with invitations for unregistered users
15359
+ */
15360
+ var UsersInviteService = /** @class */ (function (_super) {
15361
+ __extends(UsersInviteService, _super);
15362
+ function UsersInviteService() {
15363
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
15364
+ _this.modelClass = RegistrationInvite;
15365
+ _this.url = 'users/invite';
15366
+ return _this;
15367
+ }
15368
+ return UsersInviteService;
15369
+ }(RestService));
15370
+ UsersInviteService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: UsersInviteService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
15371
+ UsersInviteService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: UsersInviteService, providedIn: 'root' });
15372
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: UsersInviteService, decorators: [{
15373
+ type: i0.Injectable,
15374
+ args: [{
15375
+ providedIn: 'root'
15376
+ }]
15377
+ }] });
15378
+
15265
15379
  /**
15266
15380
  * Service that allows to work with WorkTank operations
15267
15381
  * @TODO separate vehicles and logbooks to different api
@@ -16181,6 +16295,20 @@
16181
16295
  return ResetPasswordForm;
16182
16296
  }(AbstractForm));
16183
16297
 
16298
+ /**
16299
+ * Form for inviting an unregistered user
16300
+ */
16301
+ var UserInviteForm = /** @class */ (function (_super) {
16302
+ __extends(UserInviteForm, _super);
16303
+ function UserInviteForm() {
16304
+ return _super.call(this, {
16305
+ firstName: new forms.FormControl(null, forms.Validators.required),
16306
+ email: new forms.FormControl(null, [forms.Validators.required, forms.Validators.email]),
16307
+ }, classTransformer.plainToClass(RegistrationInvite, {})) || this;
16308
+ }
16309
+ return UserInviteForm;
16310
+ }(AbstractForm));
16311
+
16184
16312
  var VehicleForm = /** @class */ (function (_super) {
16185
16313
  __extends(VehicleForm, _super);
16186
16314
  function VehicleForm(vehicle) {
@@ -17056,9 +17184,11 @@
17056
17184
  exports.UserEventType = UserEventType;
17057
17185
  exports.UserEventTypeCategory = UserEventTypeCategory;
17058
17186
  exports.UserEventTypeService = UserEventTypeService;
17187
+ exports.UserInviteForm = UserInviteForm;
17059
17188
  exports.UserService = UserService;
17060
17189
  exports.UserSwitcherService = UserSwitcherService;
17061
17190
  exports.UserToRegister = UserToRegister;
17191
+ exports.UsersInviteService = UsersInviteService;
17062
17192
  exports.Vehicle = Vehicle;
17063
17193
  exports.VehicleClaim = VehicleClaim;
17064
17194
  exports.VehicleClaimForm = VehicleClaimForm;