taxtank-core 0.23.4 → 0.23.7-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.
@@ -4,7 +4,7 @@ import * as i1$1 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import * as i1 from '@angular/common/http';
6
6
  import { HttpParams, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
7
- import { ReplaySubject, Subject, BehaviorSubject, throwError, combineLatest, of, Observable, forkJoin, from } from 'rxjs';
7
+ import { ReplaySubject, Subject, BehaviorSubject, throwError, Observable, combineLatest, of, forkJoin, from } from 'rxjs';
8
8
  import { map, filter, catchError, take, switchMap, finalize, mergeMap, distinctUntilChanged } from 'rxjs/operators';
9
9
  import { plainToClass, classToPlain, Type, Exclude, Transform, Expose } from 'class-transformer';
10
10
  import { JwtHelperService } from '@auth0/angular-jwt';
@@ -20,11 +20,11 @@ import uniqBy from 'lodash/uniqBy';
20
20
  import concat from 'lodash/concat';
21
21
  import { throwError as throwError$1 } from 'rxjs/internal/observable/throwError';
22
22
  import cloneDeep$1 from 'lodash/cloneDeep';
23
+ import { EventSourcePolyfill } from 'event-source-polyfill/src/eventsource.min.js';
23
24
  import compact from 'lodash/compact';
24
25
  import { Validators, FormGroup, FormArray, FormControl } from '@angular/forms';
25
26
  import fromPairs from 'lodash/fromPairs';
26
27
  import _ from 'lodash';
27
- import { EventSourcePolyfill } from 'event-source-polyfill/src/eventsource.min.js';
28
28
  import * as i1$2 from '@angular/router';
29
29
  import { NavigationEnd } from '@angular/router';
30
30
  import clone from 'lodash/clone';
@@ -3385,7 +3385,7 @@ class CollectionDictionary {
3385
3385
  createCollection(items = []) {
3386
3386
  return new this.collectionConstructor(items);
3387
3387
  }
3388
- length() {
3388
+ get length() {
3389
3389
  return this.keys.length;
3390
3390
  }
3391
3391
  /**
@@ -4144,6 +4144,16 @@ class BankAccountCollection extends Collection {
4144
4144
  }
4145
4145
  }
4146
4146
 
4147
+ /**
4148
+ * any event happened in the app, which needs to be handled somehow (distributed to other part of the app)
4149
+ */
4150
+ class AppEvent {
4151
+ constructor(type, payload) {
4152
+ this.type = type;
4153
+ this.payload = payload;
4154
+ }
4155
+ }
4156
+
4147
4157
  /**
4148
4158
  * BankConnection means user account at specific bank (usually each user has only one at the same bank)
4149
4159
  * service handles BankConnection management
@@ -4176,6 +4186,7 @@ class BankConnectionService extends RestService {
4176
4186
  this.cacheSubject.next(cloneDeep$1(this.cache));
4177
4187
  }
4178
4188
  }
4189
+ this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.BANK_CONNECTION_ADDED, null));
4179
4190
  return plainToClass(BankConnection, connection);
4180
4191
  }));
4181
4192
  }
@@ -4355,7 +4366,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
4355
4366
  /**
4356
4367
  * Interceptor which adds user's basiq token to any http request to basiq api
4357
4368
  */
4358
- class BasiqInterceptor {
4369
+ class BasiqTokenInterceptor {
4359
4370
  constructor(basiqTokenService) {
4360
4371
  this.basiqTokenService = basiqTokenService;
4361
4372
  }
@@ -4376,12 +4387,239 @@ class BasiqInterceptor {
4376
4387
  });
4377
4388
  }
4378
4389
  }
4379
- BasiqInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqInterceptor, deps: [{ token: BasiqTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
4380
- BasiqInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqInterceptor });
4381
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqInterceptor, decorators: [{
4390
+ BasiqTokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqTokenInterceptor, deps: [{ token: BasiqTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
4391
+ BasiqTokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqTokenInterceptor });
4392
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqTokenInterceptor, decorators: [{
4382
4393
  type: Injectable
4383
4394
  }], ctorParameters: function () { return [{ type: BasiqTokenService }]; } });
4384
4395
 
4396
+ /**
4397
+ * server sent events service
4398
+ * https://symfony.com/doc/current/mercure.html
4399
+ */
4400
+ class SseService {
4401
+ constructor(zone, jwtService, environment) {
4402
+ this.zone = zone;
4403
+ this.jwtService = jwtService;
4404
+ this.environment = environment;
4405
+ }
4406
+ /**
4407
+ * list to url for server events
4408
+ */
4409
+ on(topic) {
4410
+ const url = new URL(this.environment.mercureUrl);
4411
+ url.searchParams.append('topic', `${this.environment.apiV2}/users/${this.jwtService.decodeToken().username}/${topic}`);
4412
+ // tslint:disable-next-line:typedef
4413
+ return new Observable((observer) => {
4414
+ const es = new EventSourcePolyfill(url, {
4415
+ headers: {
4416
+ Authorization: 'Bearer ' + this.jwtService.getToken(),
4417
+ }
4418
+ });
4419
+ es.onmessage = (event) => {
4420
+ this.zone.run(() => observer.next(event));
4421
+ };
4422
+ })
4423
+ .pipe(map((messageEvent) => {
4424
+ return JSON.parse(messageEvent.data);
4425
+ }));
4426
+ }
4427
+ }
4428
+ SseService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, deps: [{ token: i0.NgZone }, { token: JwtService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
4429
+ SseService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, providedIn: 'root' });
4430
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, decorators: [{
4431
+ type: Injectable,
4432
+ args: [{
4433
+ providedIn: 'root'
4434
+ }]
4435
+ }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: JwtService }, { type: undefined, decorators: [{
4436
+ type: Inject,
4437
+ args: ['environment']
4438
+ }] }]; } });
4439
+
4440
+ /**
4441
+ * Service to work with user
4442
+ */
4443
+ class UserService {
4444
+ constructor(http, jwtService, eventDispatcherService, sseService, environment) {
4445
+ this.http = http;
4446
+ this.jwtService = jwtService;
4447
+ this.eventDispatcherService = eventDispatcherService;
4448
+ this.sseService = sseService;
4449
+ this.environment = environment;
4450
+ this.cacheSubject = new ReplaySubject(1);
4451
+ this.listenEvents();
4452
+ }
4453
+ listenEvents() {
4454
+ this.listenServiceSubscriptionUpdated();
4455
+ }
4456
+ get() {
4457
+ if (!this.cache) {
4458
+ this.fetch().subscribe(() => { }, (error) => {
4459
+ // force logout user (clear localStorage) when get current user return error
4460
+ if (error.status === 500) {
4461
+ this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.CURRENT_USER_GET_FAILED, null));
4462
+ }
4463
+ });
4464
+ }
4465
+ return this.cacheSubject.asObservable();
4466
+ }
4467
+ /**
4468
+ * Get current user
4469
+ */
4470
+ fetch() {
4471
+ return this.http.get(`${this.environment.apiV2}/users/current`)
4472
+ .pipe(map((userBase) => {
4473
+ const user = plainToClass(User, userBase);
4474
+ localStorage.setItem('userId', user.id.toString());
4475
+ // @TODO remove
4476
+ localStorage.setItem('financialYear', user.financialYear.toString());
4477
+ this.cache = user;
4478
+ this.cacheSubject.next(this.cache);
4479
+ return user;
4480
+ }));
4481
+ }
4482
+ /**
4483
+ * Register new user
4484
+ */
4485
+ register(data) {
4486
+ return this.http.post(`${this.environment.apiV2}/users/registration`, data);
4487
+ }
4488
+ /**
4489
+ * Update user
4490
+ */
4491
+ update(user) {
4492
+ return this.http.put(`${this.environment.apiV2}/users/${user.id}`, user)
4493
+ .pipe(map((userBase) => {
4494
+ this.cache = plainToClass(User, userBase);
4495
+ this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.USER_UPDATED, null));
4496
+ this.cacheSubject.next(this.cache);
4497
+ }));
4498
+ }
4499
+ /**
4500
+ * Change user password
4501
+ */
4502
+ changePassword(currentPassword, newPassword) {
4503
+ return this.http.put(`${this.environment.apiV2}/users/password/change`, { currentPassword, newPassword });
4504
+ }
4505
+ /**
4506
+ * Recovery user password
4507
+ */
4508
+ recoveryPassword(email) {
4509
+ return this.http.put(`${this.environment.apiV2}/users/password/recovery`, { email });
4510
+ }
4511
+ /**
4512
+ * Reset user password
4513
+ */
4514
+ resetPassword(newPassword, resetToken) {
4515
+ return this.http.put(`${this.environment.apiV2}/users/password/reset`, { newPassword, resetToken });
4516
+ }
4517
+ resendConfirmationEmail(email) {
4518
+ return this.http.post(`${this.environment.apiV2}/users/confirmation/resend`, { email });
4519
+ }
4520
+ /**
4521
+ * Confirm registered user
4522
+ */
4523
+ confirm(verificationCode) {
4524
+ return this.http.post(`${this.environment.apiV2}/users/confirmation`, { verificationCode });
4525
+ }
4526
+ /**
4527
+ * Search existing user
4528
+ */
4529
+ search(email) {
4530
+ return this.http.get(`${this.environment.apiV2}/users/search?email=${email}`)
4531
+ .pipe(map((userBase) => {
4532
+ return plainToClass(User, userBase);
4533
+ }));
4534
+ }
4535
+ /**
4536
+ * Finish onboarding process
4537
+ */
4538
+ finishOnboarding(user) {
4539
+ return this.http.put(`${this.environment.apiV2}/users/status`, user)
4540
+ .pipe(map(() => {
4541
+ this.cache = user;
4542
+ this.cacheSubject.next(this.cache);
4543
+ }));
4544
+ }
4545
+ /**
4546
+ * Update user photo
4547
+ */
4548
+ updatePhoto(photo) {
4549
+ return this.http.post(`${this.environment.apiV2}/users/photo?_method=PUT`, photo)
4550
+ .pipe(map((photoUrl) => {
4551
+ this.cache = plainToClass(User, Object.assign(this.cache, { photo: photoUrl }));
4552
+ this.cacheSubject.next(this.cache);
4553
+ }));
4554
+ }
4555
+ switchFinancialYear(year) {
4556
+ return this.http.get(`${this.environment.apiV2}/financial-year/switch`, { params: new HttpParams({ fromString: `financialYear=${year}` }) }).pipe(map(() => {
4557
+ localStorage.setItem('financialYear', year.toString());
4558
+ window.location.reload();
4559
+ }));
4560
+ }
4561
+ /**
4562
+ * clear service cache
4563
+ */
4564
+ resetCache() {
4565
+ this.fetch().subscribe();
4566
+ }
4567
+ /**
4568
+ * Create basiq (if not exist yet) to provide access to basiq api
4569
+ */
4570
+ createBasiq() {
4571
+ return this.http.post(`${this.environment.apiV2}/basiq/user`, {})
4572
+ .pipe(map((basiqId) => {
4573
+ this.cache = plainToClass(User, Object.assign(this.cache, { basiqId }));
4574
+ this.cacheSubject.next(this.cache);
4575
+ return basiqId;
4576
+ }));
4577
+ }
4578
+ /**
4579
+ * Update cache when user's service subscription is updated
4580
+ */
4581
+ listenServiceSubscriptionUpdated() {
4582
+ this.eventDispatcherService.on(AppEventTypeEnum.SERVICE_SUBSCRIPTION_UPDATED).subscribe(() => this.resetCache());
4583
+ }
4584
+ }
4585
+ UserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, deps: [{ token: i1.HttpClient }, { token: JwtService }, { token: EventDispatcherService }, { token: SseService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
4586
+ UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, providedIn: 'root' });
4587
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, decorators: [{
4588
+ type: Injectable,
4589
+ args: [{
4590
+ providedIn: 'root'
4591
+ }]
4592
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: EventDispatcherService }, { type: SseService }, { type: undefined, decorators: [{
4593
+ type: Inject,
4594
+ args: ['environment']
4595
+ }] }]; } });
4596
+
4597
+ /**
4598
+ * Interceptor which check if client's basiq id exist and request it if not
4599
+ */
4600
+ class BasiqClientIdInterceptor {
4601
+ constructor(userService) {
4602
+ this.userService = userService;
4603
+ }
4604
+ intercept(request, next) {
4605
+ // Check if 'client id' URL segment contains null instead of id
4606
+ if (!request.url.startsWith(`${BasiqService.basiqApiUrl}/users/null`)) {
4607
+ return next.handle(request);
4608
+ }
4609
+ return this.userService.createBasiq().pipe(mergeMap((basiqClientId) => next.handle(this.addId(request, basiqClientId))));
4610
+ }
4611
+ addId(request, basiqClientId) {
4612
+ return request.clone({
4613
+ url: request.url.replace('null', basiqClientId)
4614
+ });
4615
+ }
4616
+ }
4617
+ BasiqClientIdInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqClientIdInterceptor, deps: [{ token: UserService }], target: i0.ɵɵFactoryTarget.Injectable });
4618
+ BasiqClientIdInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqClientIdInterceptor });
4619
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqClientIdInterceptor, decorators: [{
4620
+ type: Injectable
4621
+ }], ctorParameters: function () { return [{ type: UserService }]; } });
4622
+
4385
4623
  class InterceptorsModule {
4386
4624
  }
4387
4625
  InterceptorsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: InterceptorsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -4415,7 +4653,12 @@ InterceptorsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", vers
4415
4653
  },
4416
4654
  {
4417
4655
  provide: HTTP_INTERCEPTORS,
4418
- useClass: BasiqInterceptor,
4656
+ useClass: BasiqTokenInterceptor,
4657
+ multi: true
4658
+ },
4659
+ {
4660
+ provide: HTTP_INTERCEPTORS,
4661
+ useClass: BasiqClientIdInterceptor,
4419
4662
  multi: true
4420
4663
  }
4421
4664
  ] });
@@ -4451,7 +4694,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
4451
4694
  },
4452
4695
  {
4453
4696
  provide: HTTP_INTERCEPTORS,
4454
- useClass: BasiqInterceptor,
4697
+ useClass: BasiqTokenInterceptor,
4698
+ multi: true
4699
+ },
4700
+ {
4701
+ provide: HTTP_INTERCEPTORS,
4702
+ useClass: BasiqClientIdInterceptor,
4455
4703
  multi: true
4456
4704
  }
4457
4705
  ]
@@ -7142,16 +7390,6 @@ __decorate([
7142
7390
  Type(() => User)
7143
7391
  ], EmployeeInvite.prototype, "employee", void 0);
7144
7392
 
7145
- /**
7146
- * any event happened in the app, which needs to be handled somehow (distributed to other part of the app)
7147
- */
7148
- class AppEvent {
7149
- constructor(type, payload) {
7150
- this.type = type;
7151
- this.payload = payload;
7152
- }
7153
- }
7154
-
7155
7393
  var ExportFormatEnum;
7156
7394
  (function (ExportFormatEnum) {
7157
7395
  ExportFormatEnum["PDF"] = "PDF";
@@ -9177,7 +9415,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
9177
9415
  }]
9178
9416
  }] });
9179
9417
 
9180
- var MessagesEnum$1;
9418
+ var MessagesEnum;
9181
9419
  (function (MessagesEnum) {
9182
9420
  MessagesEnum["VEHICLE_CREATED"] = "Vehicle created successfully";
9183
9421
  MessagesEnum["VEHICLE_UPDATED"] = "Vehicle updated successfully";
@@ -9188,16 +9426,16 @@ var MessagesEnum$1;
9188
9426
  MessagesEnum["VEHICLE_LOGBOOK_CREATED"] = "Vehicle logbook created successfully";
9189
9427
  MessagesEnum["VEHICLE_LOGBOOK_UPDATED"] = "Vehicle logbook updated successfully";
9190
9428
  MessagesEnum["VEHICLE_LOGBOOK_DELETED"] = "Vehicle logbook deleted successfully";
9191
- })(MessagesEnum$1 || (MessagesEnum$1 = {}));
9429
+ })(MessagesEnum || (MessagesEnum = {}));
9192
9430
 
9193
9431
  class VehicleClaimService extends RestService {
9194
9432
  constructor() {
9195
9433
  super(...arguments);
9196
9434
  this.modelClass = VehicleClaim;
9197
9435
  this.url = 'vehicle-claims';
9198
- this.messageCreated = MessagesEnum$1.VEHICLE_CLAIM_CREATED;
9199
- this.messageUpdated = MessagesEnum$1.VEHICLE_CLAIM_UPDATED;
9200
- this.messageDeleted = MessagesEnum$1.VEHICLE_CLAIM_DELETED;
9436
+ this.messageCreated = MessagesEnum.VEHICLE_CLAIM_CREATED;
9437
+ this.messageUpdated = MessagesEnum.VEHICLE_CLAIM_UPDATED;
9438
+ this.messageDeleted = MessagesEnum.VEHICLE_CLAIM_DELETED;
9201
9439
  }
9202
9440
  }
9203
9441
  VehicleClaimService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: VehicleClaimService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
@@ -9222,13 +9460,6 @@ function enumToList(data) {
9222
9460
  return list;
9223
9461
  }
9224
9462
 
9225
- var MessagesEnum;
9226
- (function (MessagesEnum) {
9227
- MessagesEnum["DELETED_MESSAGE"] = "Transaction deleted";
9228
- MessagesEnum["UPDATED_MESSAGE"] = "Transaction updated";
9229
- MessagesEnum["CREATED_MESSAGE"] = "Transaction(s) created";
9230
- })(MessagesEnum || (MessagesEnum = {}));
9231
-
9232
9463
  /**
9233
9464
  * Service for transactions business logic
9234
9465
  */
@@ -9360,7 +9591,6 @@ class TransactionService extends RestService {
9360
9591
  this.updateCache();
9361
9592
  }
9362
9593
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.TRANSACTIONS_CREATED, addedTransactions));
9363
- this.toastService.success(MessagesEnum.CREATED_MESSAGE);
9364
9594
  return addedTransactions;
9365
9595
  }));
9366
9596
  }
@@ -9397,7 +9627,6 @@ class TransactionService extends RestService {
9397
9627
  this.addBatch(childTransactionsToAdd).subscribe();
9398
9628
  }
9399
9629
  }
9400
- this.toastService.success(MessagesEnum.UPDATED_MESSAGE);
9401
9630
  replace(this.cache, updatedTransaction);
9402
9631
  this.updateCache();
9403
9632
  return updatedTransaction;
@@ -9444,7 +9673,6 @@ class TransactionService extends RestService {
9444
9673
  return transaction.id !== model.id && ((_a = transaction.parentTransaction) === null || _a === void 0 ? void 0 : _a.id) !== model.id;
9445
9674
  });
9446
9675
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.TRANSACTION_DELETED, model));
9447
- this.toastService.success(MessagesEnum.DELETED_MESSAGE);
9448
9676
  this.updateCache();
9449
9677
  this.transactionDeleted.emit(model);
9450
9678
  }));
@@ -10118,50 +10346,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
10118
10346
  }]
10119
10347
  }] });
10120
10348
 
10121
- /**
10122
- * server sent events service
10123
- * https://symfony.com/doc/current/mercure.html
10124
- */
10125
- class SseService {
10126
- constructor(zone, jwtService, environment) {
10127
- this.zone = zone;
10128
- this.jwtService = jwtService;
10129
- this.environment = environment;
10130
- }
10131
- /**
10132
- * list to url for server events
10133
- */
10134
- on(topic) {
10135
- const url = new URL(this.environment.mercureUrl);
10136
- url.searchParams.append('topic', `${this.environment.apiV2}/users/${this.jwtService.decodeToken().username}/${topic}`);
10137
- // tslint:disable-next-line:typedef
10138
- return new Observable((observer) => {
10139
- const es = new EventSourcePolyfill(url, {
10140
- headers: {
10141
- Authorization: 'Bearer ' + this.jwtService.getToken(),
10142
- }
10143
- });
10144
- es.onmessage = (event) => {
10145
- this.zone.run(() => observer.next(event));
10146
- };
10147
- })
10148
- .pipe(map((messageEvent) => {
10149
- return JSON.parse(messageEvent.data);
10150
- }));
10151
- }
10152
- }
10153
- SseService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, deps: [{ token: i0.NgZone }, { token: JwtService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
10154
- SseService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, providedIn: 'root' });
10155
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, decorators: [{
10156
- type: Injectable,
10157
- args: [{
10158
- providedIn: 'root'
10159
- }]
10160
- }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: JwtService }, { type: undefined, decorators: [{
10161
- type: Inject,
10162
- args: ['environment']
10163
- }] }]; } });
10164
-
10165
10349
  /**
10166
10350
  * Service for work with chats
10167
10351
  */
@@ -12572,152 +12756,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
12572
12756
  args: ['environment']
12573
12757
  }] }]; } });
12574
12758
 
12575
- /**
12576
- * Service to work with user
12577
- */
12578
- class UserService {
12579
- constructor(http, jwtService, eventDispatcherService, sseService, environment) {
12580
- this.http = http;
12581
- this.jwtService = jwtService;
12582
- this.eventDispatcherService = eventDispatcherService;
12583
- this.sseService = sseService;
12584
- this.environment = environment;
12585
- this.cacheSubject = new ReplaySubject(1);
12586
- this.listenEvents();
12587
- }
12588
- listenEvents() {
12589
- this.listenServiceSubscriptionUpdated();
12590
- }
12591
- get() {
12592
- if (!this.cache) {
12593
- this.fetch().subscribe(() => { }, (error) => {
12594
- // force logout user (clear localStorage) when get current user return error
12595
- if (error.status === 500) {
12596
- this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.CURRENT_USER_GET_FAILED, null));
12597
- }
12598
- });
12599
- }
12600
- return this.cacheSubject.asObservable();
12601
- }
12602
- /**
12603
- * Get current user
12604
- */
12605
- fetch() {
12606
- return this.http.get(`${this.environment.apiV2}/users/current`)
12607
- .pipe(map((userBase) => {
12608
- const user = plainToClass(User, userBase);
12609
- localStorage.setItem('userId', user.id.toString());
12610
- // @TODO remove
12611
- localStorage.setItem('financialYear', user.financialYear.toString());
12612
- this.cache = user;
12613
- this.cacheSubject.next(this.cache);
12614
- return user;
12615
- }));
12616
- }
12617
- /**
12618
- * Register new user
12619
- */
12620
- register(data) {
12621
- return this.http.post(`${this.environment.apiV2}/users/registration`, data);
12622
- }
12623
- /**
12624
- * Update user
12625
- */
12626
- update(user) {
12627
- return this.http.put(`${this.environment.apiV2}/users/${user.id}`, user)
12628
- .pipe(map((userBase) => {
12629
- this.cache = plainToClass(User, userBase);
12630
- this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.USER_UPDATED, null));
12631
- this.cacheSubject.next(this.cache);
12632
- }));
12633
- }
12634
- /**
12635
- * Change user password
12636
- */
12637
- changePassword(currentPassword, newPassword) {
12638
- return this.http.put(`${this.environment.apiV2}/users/password/change`, { currentPassword, newPassword });
12639
- }
12640
- /**
12641
- * Recovery user password
12642
- */
12643
- recoveryPassword(email) {
12644
- return this.http.put(`${this.environment.apiV2}/users/password/recovery`, { email });
12645
- }
12646
- /**
12647
- * Reset user password
12648
- */
12649
- resetPassword(newPassword, resetToken) {
12650
- return this.http.put(`${this.environment.apiV2}/users/password/reset`, { newPassword, resetToken });
12651
- }
12652
- resendConfirmationEmail(email) {
12653
- return this.http.post(`${this.environment.apiV2}/users/confirmation/resend`, { email });
12654
- }
12655
- /**
12656
- * Confirm registered user
12657
- */
12658
- confirm(verificationCode) {
12659
- return this.http.post(`${this.environment.apiV2}/users/confirmation`, { verificationCode });
12660
- }
12661
- /**
12662
- * Search existing user
12663
- */
12664
- search(email) {
12665
- return this.http.get(`${this.environment.apiV2}/users/search?email=${email}`)
12666
- .pipe(map((userBase) => {
12667
- return plainToClass(User, userBase);
12668
- }));
12669
- }
12670
- /**
12671
- * Finish onboarding process
12672
- */
12673
- finishOnboarding(user) {
12674
- return this.http.put(`${this.environment.apiV2}/users/status`, user)
12675
- .pipe(map(() => {
12676
- this.cache = user;
12677
- this.cacheSubject.next(this.cache);
12678
- }));
12679
- }
12680
- /**
12681
- * Update user photo
12682
- */
12683
- updatePhoto(photo) {
12684
- return this.http.post(`${this.environment.apiV2}/users/photo?_method=PUT`, photo)
12685
- .pipe(map((photoUrl) => {
12686
- this.cache = plainToClass(User, Object.assign(this.cache, { photo: photoUrl }));
12687
- this.cacheSubject.next(this.cache);
12688
- }));
12689
- }
12690
- switchFinancialYear(year) {
12691
- return this.http.get(`${this.environment.apiV2}/financial-year/switch`, { params: new HttpParams({ fromString: `financialYear=${year}` }) }).pipe(map(() => {
12692
- localStorage.setItem('financialYear', year.toString());
12693
- window.location.reload();
12694
- }));
12695
- }
12696
- /**
12697
- * clear service cache
12698
- */
12699
- resetCache() {
12700
- this.fetch().subscribe();
12701
- }
12702
- /**
12703
- * Update cache when user's service subscription is updated
12704
- */
12705
- listenServiceSubscriptionUpdated() {
12706
- this.eventDispatcherService.on(AppEventTypeEnum.SERVICE_SUBSCRIPTION_UPDATED).subscribe(() => this.resetCache());
12707
- }
12708
- }
12709
- UserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, deps: [{ token: i1.HttpClient }, { token: JwtService }, { token: EventDispatcherService }, { token: SseService }, { token: 'environment' }], target: i0.ɵɵFactoryTarget.Injectable });
12710
- UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, providedIn: 'root' });
12711
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, decorators: [{
12712
- type: Injectable,
12713
- args: [{
12714
- providedIn: 'root'
12715
- }]
12716
- }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: EventDispatcherService }, { type: SseService }, { type: undefined, decorators: [{
12717
- type: Inject,
12718
- args: ['environment']
12719
- }] }]; } });
12720
-
12721
12759
  class UserEventSettingService extends RestService {
12722
12760
  constructor() {
12723
12761
  super(...arguments);
@@ -12787,9 +12825,9 @@ class VehicleService extends RestService {
12787
12825
  super(...arguments);
12788
12826
  this.url = 'vehicles';
12789
12827
  this.modelClass = Vehicle;
12790
- this.messageCreated = MessagesEnum$1.VEHICLE_CREATED;
12791
- this.messageUpdated = MessagesEnum$1.VEHICLE_UPDATED;
12792
- this.messageDeleted = MessagesEnum$1.VEHICLE_DELETED;
12828
+ this.messageCreated = MessagesEnum.VEHICLE_CREATED;
12829
+ this.messageUpdated = MessagesEnum.VEHICLE_UPDATED;
12830
+ this.messageDeleted = MessagesEnum.VEHICLE_DELETED;
12793
12831
  }
12794
12832
  listenEvents() {
12795
12833
  this.listenLogbookAdded();
@@ -12859,7 +12897,7 @@ class VehicleLogbookService {
12859
12897
  .pipe(map((vehicleLogbookBase) => {
12860
12898
  const newVehicleLogbook = plainToClass(VehicleLogbook, vehicleLogbookBase);
12861
12899
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_LOGBOOK_CREATED, { logbook: newVehicleLogbook, vehicleId }));
12862
- this.toastService.success(MessagesEnum$1.VEHICLE_LOGBOOK_CREATED);
12900
+ this.toastService.success(MessagesEnum.VEHICLE_LOGBOOK_CREATED);
12863
12901
  return newVehicleLogbook;
12864
12902
  }));
12865
12903
  }
@@ -12867,7 +12905,7 @@ class VehicleLogbookService {
12867
12905
  return this.http.put(`${this.environment.apiV2}/vehicles/${vehicleId}/logbooks/${logbook.id}`, logbook).pipe(map((vehicleLogbookBase) => {
12868
12906
  const updatedVehicleLogbook = plainToClass(VehicleLogbook, vehicleLogbookBase);
12869
12907
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_LOGBOOK_UPDATED, { logbook: updatedVehicleLogbook, vehicleId }));
12870
- this.toastService.success(MessagesEnum$1.VEHICLE_LOGBOOK_UPDATED);
12908
+ this.toastService.success(MessagesEnum.VEHICLE_LOGBOOK_UPDATED);
12871
12909
  return plainToClass(VehicleLogbook, updatedVehicleLogbook);
12872
12910
  }));
12873
12911
  }
@@ -12875,7 +12913,7 @@ class VehicleLogbookService {
12875
12913
  return this.http.delete(`${this.environment.apiV2}/vehicles/${vehicleId}/logbooks/${logbook.id}`)
12876
12914
  .pipe(map(() => {
12877
12915
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_LOGBOOK_DELETED, { logbook, vehicleId }));
12878
- this.toastService.success(MessagesEnum$1.VEHICLE_LOGBOOK_DELETED);
12916
+ this.toastService.success(MessagesEnum.VEHICLE_LOGBOOK_DELETED);
12879
12917
  }));
12880
12918
  }
12881
12919
  }