add show
This commit is contained in:
@@ -1,40 +1,17 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {AngularFirestore, AngularFirestoreCollection} from '@angular/fire/firestore';
|
||||
import {Song} from '../models/song';
|
||||
import {Song} from './song';
|
||||
import {Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {AngularFirestoreDocument} from '@angular/fire/firestore/document/document';
|
||||
import {DbService} from '../../../services/db.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SongDataService {
|
||||
private songCollection: AngularFirestoreCollection<Song>;
|
||||
private readonly songs: Observable<Song[]>;
|
||||
|
||||
constructor(private afs: AngularFirestore) {
|
||||
this.songCollection = afs.collection<Song>('songs');
|
||||
this.songs = this.songCollection.snapshotChanges().pipe(map(actions => {
|
||||
return actions.map(a => ({
|
||||
...a.payload.doc.data(),
|
||||
id: a.payload.doc.id
|
||||
}));
|
||||
}));
|
||||
constructor(private dbService: DbService) {
|
||||
}
|
||||
|
||||
public list = (): Observable<Song[]> => this.songs;
|
||||
|
||||
public getSongRef = (songId: string): AngularFirestoreDocument<Song> => this.afs.doc<Song>('songs/' + songId);
|
||||
|
||||
public read(songId: string): Observable<Song | undefined> {
|
||||
return this.getSongRef(songId).valueChanges().pipe(map(song => ({
|
||||
...song,
|
||||
id: songId
|
||||
} as Song)));
|
||||
}
|
||||
|
||||
public async update(songId: string, data: any): Promise<void> {
|
||||
await this.getSongRef(songId).update(data);
|
||||
}
|
||||
public list$ = (): Observable<Song[]> => this.dbService.col$('songs');
|
||||
public read$ = (songId: string): Observable<Song | undefined> => this.dbService.doc$('songs/' + songId);
|
||||
public update = async (songId: string, data: any): Promise<void> => await this.dbService.doc(songId).update(data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user