export function customerWithConfigExists()

in src/app/accounting/payroll/form/validator/customer-payroll-exists.validator.ts [30:45]


export function customerWithConfigExists(customerService: CustomerService, payrollService: PayrollService): AsyncValidatorFn {
  return (control: AbstractControl): Observable<any> => {
    if (!control.dirty || !control.value || control.value.length === 0) {
      return Observable.of(null);
    }

    if (isString(control.value) && control.value.trim().length === 0) {
      return invalid;
    }

    return customerService.getCustomer(control.value, true)
      .switchMap(customer => payrollService.findPayrollConfiguration(customer.identifier, true))
      .map(config => null)
      .catch(() => invalid);
  };
}