import { Injectable } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { environment } from '../../environments/environment'; import { User } from '../_models/user'; @Injectable({ providedIn: 'root' }) export class AuthenticationService { private userSubject: BehaviorSubject; public user: Observable; //private userLocation: BehaviorSubject; //currentLocation: Observable; constructor(private httpClient: HttpClient ) { this.userSubject = new BehaviorSubject(JSON.parse(localStorage.getItem('user'))); this.user = this.userSubject.asObservable(); //this.userLocation = new BehaviorSubject(JSON.parse(localStorage.getItem('user')).location); //this.currentLocation = this.userLocation.asObservable(); } public get userValue(): User { return this.userSubject.value; } setUser(user) { this.userSubject.next(user); } setLogin(user) { localStorage.setItem('user', JSON.stringify(user)); this.userSubject.next(user); } // changeLocation(locationId){ // this.userLocation.next(locationId); // } login(customerProfile) { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.httpClient.post(`${environment.apiUrl}/api/v1/customer_profiles/login`, customerProfile, httpOptions) } addCustomerProfile(customerProfile) { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.httpClient.post(`${environment.apiUrl}/api/v1/customer_profiles`, customerProfile, httpOptions) } async isValidSSO(sso) { return await this.httpClient.get(`${environment.apiUrl}/api/v1/customer_profiles/isValidSSO/${sso}`).toPromise(); } async isAdmin(sso) { return await this.httpClient.get(`${environment.apiUrl}/api/v1/customer_profiles/isAdmin/${sso}`).toPromise(); } logout() { localStorage.removeItem('user'); } getWalletValue(sso){ return this.httpClient.get(`${environment.apiUrl}/api/v1/customer_profiles/walletAmount/${sso}`); } getAllUsers() { return this.httpClient.get(`${environment.apiUrl}/api/v1/customer_profiles`); } getAllCustomersByCreatedDate() { return this.httpClient.get(`${environment.apiUrl}/api/v1/customer_profiles/getCustomersByCreatedDate`); } updateWalletValue(form){ return this.httpClient.put(`${environment.apiUrl}/api/v1/customer_profiles/updateWallet`, form); } deleteUser(sso){ return this.httpClient.delete(`${environment.apiUrl}/api/v1/customer_profiles/${sso}`); } updatePassword(form){ const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.httpClient.put(`${environment.apiUrl}/api/v1/customer_profiles/updatePassword`, form, httpOptions) } }