This commit is contained in:
2020-03-07 23:00:11 +01:00
committed by smuddy
parent ccd91aa81c
commit d68cd590ad
57 changed files with 2012 additions and 3489 deletions

View File

@@ -1,27 +1,27 @@
import {Injectable} from '@angular/core';
import {SongDataService} from './song-data.service';
import {File} from './file';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {FileServer} from './fileServer';
import {DbService} from '../../../services/db.service';
@Injectable({
providedIn: 'root'
})
export class FileDataService {
constructor(private songDataService: SongDataService) {
constructor(private db: DbService) {
}
public async put(songId: string, file: FileServer): Promise<string> {
const songRef = this.songDataService.getSongRef(songId);
public async set(songId: string, file: FileServer): Promise<string> {
const songRef = this.db.doc('songs/' + songId);
const fileCollection = songRef.collection('files');
const id = await fileCollection.add(file);
return id.id;
}
public get$(songId: string): Observable<File[]> {
const songRef = this.songDataService.getSongRef(songId);
public read$(songId: string): Observable<File[]> {
const songRef = this.db.doc('songs/' + songId);
return songRef.collection<File>('files').snapshotChanges().pipe(map(actions => {
return actions.map(a => ({
...a.payload.doc.data(),