import { Injectable } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { Poll } from '../models/poll.model'; import { ApiService } from './api.service'; @Injectable({ providedIn: 'root', }) export class PollService { private _poll: BehaviorSubject = new BehaviorSubject(undefined); constructor(private apiService: ApiService) {} public get poll(): Observable { return this._poll.asObservable(); } public updateCurrentPoll(poll: Poll): void { this._poll.next(poll); } public savePoll(poll: Poll): void { this.apiService.savePoll(poll); } public saveVote(poll: Poll): void { this.apiService.saveVote(poll); } public saveComment(poll: Poll, comment: string): void { this.apiService.saveComment(poll, comment); } public deletePollVotes(poll: Poll): void { this.apiService.deletePollVotes(poll); } public deletePollComments(poll: Poll): void { this.apiService.deletePollComments(poll); } }