38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
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<Speech>('speechTimes');
|
|
speechTimesRef.push({
|
|
sessionKey: sessionKey,
|
|
factionKey: factionKey,
|
|
timeInMilliseconds: timeInMilliseconds,
|
|
type: type,
|
|
});
|
|
}
|
|
|
|
public deleteSpeechTimes(sessionKey: string): void {
|
|
const speechTimesRef = this.database.list<Speech>('speechTimes');
|
|
const affectedTimes = speechTimesRef.query.orderByChild('sessionKey').equalTo(sessionKey);
|
|
affectedTimes.once('value', snapshot => {
|
|
const promises: Promise<any>[] = [];
|
|
snapshot.forEach((child) => {
|
|
promises.push(child.ref.remove());
|
|
});
|
|
Promise.all(promises);
|
|
})
|
|
}
|
|
}
|