export function employeeExists()

in src/app/common/validator/employee-exists.validator.ts [28:42]


export function employeeExists(officeService: OfficeService): 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 officeService.getEmployee(control.value, true)
      .map(employee => null)
      .catch(() => invalid);
  };
}