All files / projects/organization-management/src/app/pages/user-edit-budget user-edit-budget-page.component.ts

69.23% Statements 9/13
27.27% Branches 3/11
66.66% Functions 2/3
69.23% Lines 9/13

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 51 52 53 541x 1x         1x                 1x 1x         1x     1x 1x 1x                                                      
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { Observable } from 'rxjs';
 
import { HttpError } from 'ish-core/models/http-error/http-error.model';
 
import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
import { UserBudget } from '../../models/user-budget/user-budget.model';
 
@Component({
  selector: 'ish-user-edit-budget-page',
  templateUrl: './user-edit-budget-page.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UserEditBudgetPageComponent implements OnInit {
  constructor(private organizationManagementFacade: OrganizationManagementFacade) {}
  selectedUser$: Observable<B2bUser>;
  loading$: Observable<boolean>;
  error$: Observable<HttpError>;
 
  budgetForm = new UntypedFormGroup({});
 
  ngOnInit() {
    this.loading$ = this.organizationManagementFacade.usersLoading$;
    this.error$ = this.organizationManagementFacade.usersError$;
    this.selectedUser$ = this.organizationManagementFacade.selectedUser$;
  }
 
  submitForm() {
    Iif (this.budgetForm.valid) {
      const formValue = this.budgetForm.value;
 
      const budget: UserBudget = formValue
        ? {
            budget: formValue.budgetValue
              ? { value: formValue.budgetValue, currency: formValue.currency, type: 'Money' }
              : undefined,
            budgetPeriod: formValue.budgetPeriod,
            orderSpentLimit: formValue.orderSpentLimitValue
              ? {
                  value: formValue.orderSpentLimitValue,
                  currency: formValue.currency,
                  type: 'Money',
                }
              : undefined,
          }
        : undefined;
 
      this.organizationManagementFacade.setSelectedUserBudget(budget);
    }
  }
}