import { Injectable } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { User } from '../models/user.model'; import { ApiService } from './api.service'; @Injectable({ providedIn: 'root', }) export class UserService { public anonymous: User = new User(); private _user: BehaviorSubject = new BehaviorSubject(this.anonymous); public readonly user: Observable = this._user.asObservable(); constructor(private apiService: ApiService) {} public updateUser(user: User): void { this._user.next(user); } // GET public async getUserPolls(): Promise { const currentUser: User = this._user.getValue(); currentUser.polls = await this.apiService.getPollsByUserEmail(currentUser); this.updateUser(currentUser); } // POST public async sendEmailToUserTheListOfItsPolls(): Promise { await this.apiService.sendEmailToUserOfItsPollsList(this._user.getValue()); } }