import {Injectable} from '@angular/core'; import {BehaviorSubject, Observable} from 'rxjs'; import {DbService} from '../../../services/db.service'; import {Show} from './show'; import {map} from 'rxjs/operators'; @Injectable({ providedIn: 'root', }) export class ShowDataService { public list$ = new BehaviorSubject([]); private collection = 'shows'; public constructor(private dbService: DbService) { this.dbService.col$(this.collection).subscribe(_ => this.list$.next(_)); } public listRaw$ = () => this.dbService.col$(this.collection); public read$ = (showId: string): Observable => this.list$.pipe(map(_ => _.find(s => s.id === showId) || null)); // public list$ = (): Observable => this.dbService.col$(this.collection); // public read$ = (showId: string): Observable => this.dbService.doc$(`${this.collection}/${showId}`); public update = async (showId: string, data: Partial): Promise => await this.dbService.doc(`${this.collection}/${showId}`).update(data); public add = async (data: Partial): Promise => (await this.dbService.col(this.collection).add(data)).id; }