import { Injectable } from '@angular/core'; import {AngularFireDatabase} from '@angular/fire/compat/database'; import {SpeechType} from '../edit/time-tracking/speech-type'; import {Speech} from '../edit/time-tracking/speech'; @Injectable({ providedIn: 'root' }) export class SpeechTimeService { constructor(private database: AngularFireDatabase) { } public recordTime(sessionKey: string | undefined, factionKey: string, timeInMilliseconds: number, type: SpeechType): void { if (sessionKey == null) { return; } const speechTimesRef = this.database.list('speechTimes'); speechTimesRef.push({ sessionKey: sessionKey, factionKey: factionKey, timeInMilliseconds: timeInMilliseconds, type: type, }); } public deleteSpeechTimes(sessionKey: string): void { const speechTimesRef = this.database.list('speechTimes'); const affectedTimes = speechTimesRef.query.orderByChild('sessionKey').equalTo(sessionKey); affectedTimes.once('value', snapshot => { const promises: Promise[] = []; snapshot.forEach((child) => { promises.push(child.ref.remove()); }); Promise.all(promises); }) } }