Untitled

mail@pastecode.io avatar
unknown
typescript
2 years ago
964 B
10
Indexable
Never
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { map } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class UsersService {


  constructor(private http: HttpClient) { }



  fetchUsers() {
    return this.http.get(
      'https://moj-projekt-123.firebasedatabase.app/users.json',
    )
  }

  findUserByEmail(email: string) {
    return this.http.get(
      'https://moj-projekt-123.firebasedatabase.app/users.json'
    ).pipe(
      map(users => {
        const usersArray = [];
        for (const key in users) {
          if (users.hasOwnProperty(key)) {
            usersArray.push({ ...users[key], id: key })
          }
        }
        return usersArray;
      }),
      map(users => {
        let userExits: boolean;
        userExits = users.some(user => user.email == email);
        return userExits;
      })
    )
  }

  


}