All files / src/app/extensions/punchout/pages/account-punchout account-punchout-page.component.ts

100% Statements 20/20
75% Branches 12/16
100% Functions 6/6
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x   1x   1x 1x     1x               1x             6x       6x 6x 6x       5x   5x 5x 5x 5x 5x 5x   1x         1x      
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
 
import { AccountFacade } from 'ish-core/facades/account.facade';
import { AppFacade } from 'ish-core/facades/app.facade';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
 
import { PunchoutFacade } from '../../facades/punchout.facade';
import { PunchoutType, PunchoutUser } from '../../models/punchout-user/punchout-user.model';
 
@Component({
  selector: 'ish-account-punchout-page',
  templateUrl: './account-punchout-page.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AccountPunchoutPageComponent implements OnInit {
  punchoutTypes$: Observable<PunchoutType[]>;
  punchoutUsers$: Observable<PunchoutUser[]>;
  selectedPunchoutType$: Observable<PunchoutType>;
  loading$: Observable<boolean>;
  error$: Observable<HttpError>;
 
  ociPunchoutUrl = `${window.location.origin}/punchout?USERNAME=<USERNAME>&PASSWORD=<PASSWORD>&HOOK_URL=<HOOK_URL>`;
  cxmlPunchoutUrl$: Observable<string>;
 
  constructor(
    private accountFacade: AccountFacade,
    private appFacade: AppFacade,
    private punchoutFacade: PunchoutFacade
  ) {}
 
  ngOnInit() {
    this.punchoutUsers$ = this.punchoutFacade
      .punchoutUsersByRoute$()
      .pipe(map(users => users.sort((u1, u2) => (u1.login > u2.login ? 1 : -1))));
    this.punchoutTypes$ = this.punchoutFacade.supportedPunchoutTypes$;
    this.selectedPunchoutType$ = this.punchoutFacade.selectedPunchoutType$;
    this.loading$ = this.punchoutFacade.punchoutLoading$;
    this.error$ = this.punchoutFacade.punchoutError$ || this.punchoutFacade.punchoutTypesError$;
    this.cxmlPunchoutUrl$ = this.appFacade.getRestEndpoint$.pipe(
      withLatestFrom(this.accountFacade.customer$),
      map(([url, customer]) => `${url}/customers/${customer?.customerNo}/punchouts/cxml1.2/setuprequest`)
    );
  }
 
  deleteUser(user: PunchoutUser) {
    this.punchoutFacade.deletePunchoutUser(user);
  }
}