taxtank-core 0.23.6 → 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';
@@ -4366,7 +4366,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
4366
4366
  /**
4367
4367
  * Interceptor which adds user's basiq token to any http request to basiq api
4368
4368
  */
4369
- class BasiqInterceptor {
4369
+ class BasiqTokenInterceptor {
4370
4370
  constructor(basiqTokenService) {
4371
4371
  this.basiqTokenService = basiqTokenService;
4372
4372
  }
@@ -4387,12 +4387,239 @@ class BasiqInterceptor {
4387
4387
  });
4388
4388
  }
4389
4389
  }
4390
- BasiqInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqInterceptor, deps: [{ token: BasiqTokenService }], target: i0.ɵɵFactoryTarget.Injectable });
4391
- BasiqInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: BasiqInterceptor });
4392
- 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: [{
4393
4393
  type: Injectable
4394
4394
  }], ctorParameters: function () { return [{ type: BasiqTokenService }]; } });
4395
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
+
4396
4623
  class InterceptorsModule {
4397
4624
  }
4398
4625
  InterceptorsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: InterceptorsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -4426,7 +4653,12 @@ InterceptorsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", vers
4426
4653
  },
4427
4654
  {
4428
4655
  provide: HTTP_INTERCEPTORS,
4429
- useClass: BasiqInterceptor,
4656
+ useClass: BasiqTokenInterceptor,
4657
+ multi: true
4658
+ },
4659
+ {
4660
+ provide: HTTP_INTERCEPTORS,
4661
+ useClass: BasiqClientIdInterceptor,
4430
4662
  multi: true
4431
4663
  }
4432
4664
  ] });
@@ -4462,7 +4694,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
4462
4694
  },
4463
4695
  {
4464
4696
  provide: HTTP_INTERCEPTORS,
4465
- useClass: BasiqInterceptor,
4697
+ useClass: BasiqTokenInterceptor,
4698
+ multi: true
4699
+ },
4700
+ {
4701
+ provide: HTTP_INTERCEPTORS,
4702
+ useClass: BasiqClientIdInterceptor,
4466
4703
  multi: true
4467
4704
  }
4468
4705
  ]
@@ -9178,7 +9415,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
9178
9415
  }]
9179
9416
  }] });
9180
9417
 
9181
- var MessagesEnum$1;
9418
+ var MessagesEnum;
9182
9419
  (function (MessagesEnum) {
9183
9420
  MessagesEnum["VEHICLE_CREATED"] = "Vehicle created successfully";
9184
9421
  MessagesEnum["VEHICLE_UPDATED"] = "Vehicle updated successfully";
@@ -9189,16 +9426,16 @@ var MessagesEnum$1;
9189
9426
  MessagesEnum["VEHICLE_LOGBOOK_CREATED"] = "Vehicle logbook created successfully";
9190
9427
  MessagesEnum["VEHICLE_LOGBOOK_UPDATED"] = "Vehicle logbook updated successfully";
9191
9428
  MessagesEnum["VEHICLE_LOGBOOK_DELETED"] = "Vehicle logbook deleted successfully";
9192
- })(MessagesEnum$1 || (MessagesEnum$1 = {}));
9429
+ })(MessagesEnum || (MessagesEnum = {}));
9193
9430
 
9194
9431
  class VehicleClaimService extends RestService {
9195
9432
  constructor() {
9196
9433
  super(...arguments);
9197
9434
  this.modelClass = VehicleClaim;
9198
9435
  this.url = 'vehicle-claims';
9199
- this.messageCreated = MessagesEnum$1.VEHICLE_CLAIM_CREATED;
9200
- this.messageUpdated = MessagesEnum$1.VEHICLE_CLAIM_UPDATED;
9201
- 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;
9202
9439
  }
9203
9440
  }
9204
9441
  VehicleClaimService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: VehicleClaimService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
@@ -9223,13 +9460,6 @@ function enumToList(data) {
9223
9460
  return list;
9224
9461
  }
9225
9462
 
9226
- var MessagesEnum;
9227
- (function (MessagesEnum) {
9228
- MessagesEnum["DELETED_MESSAGE"] = "Transaction deleted";
9229
- MessagesEnum["UPDATED_MESSAGE"] = "Transaction updated";
9230
- MessagesEnum["CREATED_MESSAGE"] = "Transaction(s) created";
9231
- })(MessagesEnum || (MessagesEnum = {}));
9232
-
9233
9463
  /**
9234
9464
  * Service for transactions business logic
9235
9465
  */
@@ -9361,7 +9591,6 @@ class TransactionService extends RestService {
9361
9591
  this.updateCache();
9362
9592
  }
9363
9593
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.TRANSACTIONS_CREATED, addedTransactions));
9364
- this.toastService.success(MessagesEnum.CREATED_MESSAGE);
9365
9594
  return addedTransactions;
9366
9595
  }));
9367
9596
  }
@@ -9398,7 +9627,6 @@ class TransactionService extends RestService {
9398
9627
  this.addBatch(childTransactionsToAdd).subscribe();
9399
9628
  }
9400
9629
  }
9401
- this.toastService.success(MessagesEnum.UPDATED_MESSAGE);
9402
9630
  replace(this.cache, updatedTransaction);
9403
9631
  this.updateCache();
9404
9632
  return updatedTransaction;
@@ -9445,7 +9673,6 @@ class TransactionService extends RestService {
9445
9673
  return transaction.id !== model.id && ((_a = transaction.parentTransaction) === null || _a === void 0 ? void 0 : _a.id) !== model.id;
9446
9674
  });
9447
9675
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.TRANSACTION_DELETED, model));
9448
- this.toastService.success(MessagesEnum.DELETED_MESSAGE);
9449
9676
  this.updateCache();
9450
9677
  this.transactionDeleted.emit(model);
9451
9678
  }));
@@ -10119,50 +10346,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
10119
10346
  }]
10120
10347
  }] });
10121
10348
 
10122
- /**
10123
- * server sent events service
10124
- * https://symfony.com/doc/current/mercure.html
10125
- */
10126
- class SseService {
10127
- constructor(zone, jwtService, environment) {
10128
- this.zone = zone;
10129
- this.jwtService = jwtService;
10130
- this.environment = environment;
10131
- }
10132
- /**
10133
- * list to url for server events
10134
- */
10135
- on(topic) {
10136
- const url = new URL(this.environment.mercureUrl);
10137
- url.searchParams.append('topic', `${this.environment.apiV2}/users/${this.jwtService.decodeToken().username}/${topic}`);
10138
- // tslint:disable-next-line:typedef
10139
- return new Observable((observer) => {
10140
- const es = new EventSourcePolyfill(url, {
10141
- headers: {
10142
- Authorization: 'Bearer ' + this.jwtService.getToken(),
10143
- }
10144
- });
10145
- es.onmessage = (event) => {
10146
- this.zone.run(() => observer.next(event));
10147
- };
10148
- })
10149
- .pipe(map((messageEvent) => {
10150
- return JSON.parse(messageEvent.data);
10151
- }));
10152
- }
10153
- }
10154
- 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 });
10155
- SseService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, providedIn: 'root' });
10156
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SseService, decorators: [{
10157
- type: Injectable,
10158
- args: [{
10159
- providedIn: 'root'
10160
- }]
10161
- }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: JwtService }, { type: undefined, decorators: [{
10162
- type: Inject,
10163
- args: ['environment']
10164
- }] }]; } });
10165
-
10166
10349
  /**
10167
10350
  * Service for work with chats
10168
10351
  */
@@ -12573,152 +12756,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
12573
12756
  args: ['environment']
12574
12757
  }] }]; } });
12575
12758
 
12576
- /**
12577
- * Service to work with user
12578
- */
12579
- class UserService {
12580
- constructor(http, jwtService, eventDispatcherService, sseService, environment) {
12581
- this.http = http;
12582
- this.jwtService = jwtService;
12583
- this.eventDispatcherService = eventDispatcherService;
12584
- this.sseService = sseService;
12585
- this.environment = environment;
12586
- this.cacheSubject = new ReplaySubject(1);
12587
- this.listenEvents();
12588
- }
12589
- listenEvents() {
12590
- this.listenServiceSubscriptionUpdated();
12591
- }
12592
- get() {
12593
- if (!this.cache) {
12594
- this.fetch().subscribe(() => { }, (error) => {
12595
- // force logout user (clear localStorage) when get current user return error
12596
- if (error.status === 500) {
12597
- this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.CURRENT_USER_GET_FAILED, null));
12598
- }
12599
- });
12600
- }
12601
- return this.cacheSubject.asObservable();
12602
- }
12603
- /**
12604
- * Get current user
12605
- */
12606
- fetch() {
12607
- return this.http.get(`${this.environment.apiV2}/users/current`)
12608
- .pipe(map((userBase) => {
12609
- const user = plainToClass(User, userBase);
12610
- localStorage.setItem('userId', user.id.toString());
12611
- // @TODO remove
12612
- localStorage.setItem('financialYear', user.financialYear.toString());
12613
- this.cache = user;
12614
- this.cacheSubject.next(this.cache);
12615
- return user;
12616
- }));
12617
- }
12618
- /**
12619
- * Register new user
12620
- */
12621
- register(data) {
12622
- return this.http.post(`${this.environment.apiV2}/users/registration`, data);
12623
- }
12624
- /**
12625
- * Update user
12626
- */
12627
- update(user) {
12628
- return this.http.put(`${this.environment.apiV2}/users/${user.id}`, user)
12629
- .pipe(map((userBase) => {
12630
- this.cache = plainToClass(User, userBase);
12631
- this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.USER_UPDATED, null));
12632
- this.cacheSubject.next(this.cache);
12633
- }));
12634
- }
12635
- /**
12636
- * Change user password
12637
- */
12638
- changePassword(currentPassword, newPassword) {
12639
- return this.http.put(`${this.environment.apiV2}/users/password/change`, { currentPassword, newPassword });
12640
- }
12641
- /**
12642
- * Recovery user password
12643
- */
12644
- recoveryPassword(email) {
12645
- return this.http.put(`${this.environment.apiV2}/users/password/recovery`, { email });
12646
- }
12647
- /**
12648
- * Reset user password
12649
- */
12650
- resetPassword(newPassword, resetToken) {
12651
- return this.http.put(`${this.environment.apiV2}/users/password/reset`, { newPassword, resetToken });
12652
- }
12653
- resendConfirmationEmail(email) {
12654
- return this.http.post(`${this.environment.apiV2}/users/confirmation/resend`, { email });
12655
- }
12656
- /**
12657
- * Confirm registered user
12658
- */
12659
- confirm(verificationCode) {
12660
- return this.http.post(`${this.environment.apiV2}/users/confirmation`, { verificationCode });
12661
- }
12662
- /**
12663
- * Search existing user
12664
- */
12665
- search(email) {
12666
- return this.http.get(`${this.environment.apiV2}/users/search?email=${email}`)
12667
- .pipe(map((userBase) => {
12668
- return plainToClass(User, userBase);
12669
- }));
12670
- }
12671
- /**
12672
- * Finish onboarding process
12673
- */
12674
- finishOnboarding(user) {
12675
- return this.http.put(`${this.environment.apiV2}/users/status`, user)
12676
- .pipe(map(() => {
12677
- this.cache = user;
12678
- this.cacheSubject.next(this.cache);
12679
- }));
12680
- }
12681
- /**
12682
- * Update user photo
12683
- */
12684
- updatePhoto(photo) {
12685
- return this.http.post(`${this.environment.apiV2}/users/photo?_method=PUT`, photo)
12686
- .pipe(map((photoUrl) => {
12687
- this.cache = plainToClass(User, Object.assign(this.cache, { photo: photoUrl }));
12688
- this.cacheSubject.next(this.cache);
12689
- }));
12690
- }
12691
- switchFinancialYear(year) {
12692
- return this.http.get(`${this.environment.apiV2}/financial-year/switch`, { params: new HttpParams({ fromString: `financialYear=${year}` }) }).pipe(map(() => {
12693
- localStorage.setItem('financialYear', year.toString());
12694
- window.location.reload();
12695
- }));
12696
- }
12697
- /**
12698
- * clear service cache
12699
- */
12700
- resetCache() {
12701
- this.fetch().subscribe();
12702
- }
12703
- /**
12704
- * Update cache when user's service subscription is updated
12705
- */
12706
- listenServiceSubscriptionUpdated() {
12707
- this.eventDispatcherService.on(AppEventTypeEnum.SERVICE_SUBSCRIPTION_UPDATED).subscribe(() => this.resetCache());
12708
- }
12709
- }
12710
- 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 });
12711
- UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, providedIn: 'root' });
12712
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: UserService, decorators: [{
12713
- type: Injectable,
12714
- args: [{
12715
- providedIn: 'root'
12716
- }]
12717
- }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: JwtService }, { type: EventDispatcherService }, { type: SseService }, { type: undefined, decorators: [{
12718
- type: Inject,
12719
- args: ['environment']
12720
- }] }]; } });
12721
-
12722
12759
  class UserEventSettingService extends RestService {
12723
12760
  constructor() {
12724
12761
  super(...arguments);
@@ -12788,9 +12825,9 @@ class VehicleService extends RestService {
12788
12825
  super(...arguments);
12789
12826
  this.url = 'vehicles';
12790
12827
  this.modelClass = Vehicle;
12791
- this.messageCreated = MessagesEnum$1.VEHICLE_CREATED;
12792
- this.messageUpdated = MessagesEnum$1.VEHICLE_UPDATED;
12793
- this.messageDeleted = MessagesEnum$1.VEHICLE_DELETED;
12828
+ this.messageCreated = MessagesEnum.VEHICLE_CREATED;
12829
+ this.messageUpdated = MessagesEnum.VEHICLE_UPDATED;
12830
+ this.messageDeleted = MessagesEnum.VEHICLE_DELETED;
12794
12831
  }
12795
12832
  listenEvents() {
12796
12833
  this.listenLogbookAdded();
@@ -12860,7 +12897,7 @@ class VehicleLogbookService {
12860
12897
  .pipe(map((vehicleLogbookBase) => {
12861
12898
  const newVehicleLogbook = plainToClass(VehicleLogbook, vehicleLogbookBase);
12862
12899
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_LOGBOOK_CREATED, { logbook: newVehicleLogbook, vehicleId }));
12863
- this.toastService.success(MessagesEnum$1.VEHICLE_LOGBOOK_CREATED);
12900
+ this.toastService.success(MessagesEnum.VEHICLE_LOGBOOK_CREATED);
12864
12901
  return newVehicleLogbook;
12865
12902
  }));
12866
12903
  }
@@ -12868,7 +12905,7 @@ class VehicleLogbookService {
12868
12905
  return this.http.put(`${this.environment.apiV2}/vehicles/${vehicleId}/logbooks/${logbook.id}`, logbook).pipe(map((vehicleLogbookBase) => {
12869
12906
  const updatedVehicleLogbook = plainToClass(VehicleLogbook, vehicleLogbookBase);
12870
12907
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_LOGBOOK_UPDATED, { logbook: updatedVehicleLogbook, vehicleId }));
12871
- this.toastService.success(MessagesEnum$1.VEHICLE_LOGBOOK_UPDATED);
12908
+ this.toastService.success(MessagesEnum.VEHICLE_LOGBOOK_UPDATED);
12872
12909
  return plainToClass(VehicleLogbook, updatedVehicleLogbook);
12873
12910
  }));
12874
12911
  }
@@ -12876,7 +12913,7 @@ class VehicleLogbookService {
12876
12913
  return this.http.delete(`${this.environment.apiV2}/vehicles/${vehicleId}/logbooks/${logbook.id}`)
12877
12914
  .pipe(map(() => {
12878
12915
  this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_LOGBOOK_DELETED, { logbook, vehicleId }));
12879
- this.toastService.success(MessagesEnum$1.VEHICLE_LOGBOOK_DELETED);
12916
+ this.toastService.success(MessagesEnum.VEHICLE_LOGBOOK_DELETED);
12880
12917
  }));
12881
12918
  }
12882
12919
  }