import {Injectable} from '@angular/core'; import {ShowSongDataService} from './show-song-data.service'; import {Observable} from 'rxjs'; import {ShowSong} from './showSong'; import {SongDataService} from '../../songs/services/song-data.service'; import {take} from 'rxjs/operators'; @Injectable({ providedIn: 'root' }) export class ShowSongService { constructor( private showSongDataService: ShowSongDataService, private songDataService: SongDataService ) { } public async new$(showId: string, songId: string, order: number): Promise { const song = await this.songDataService.read$(songId).pipe(take(1)).toPromise(); const data = {songId, order, key: song.key, keyOriginal: song.key}; return await this.showSongDataService.add(showId, data); } public list$ = (showId: string): Observable => this.showSongDataService.list$(showId, _ => _.orderBy('order')); public delete$ = (showId: string, songId: string): Promise => this.showSongDataService.delete(showId, songId); public update$ = async (showId: string, songId: string, data: Partial): Promise => await this.showSongDataService.update$(showId, songId, data); }