35 lines
998 B
TypeScript
35 lines
998 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import {AngularFireDatabase} from '@angular/fire/compat/database';
|
|
import {Session} from '../edit/session';
|
|
import {SpeechTimeService} from './speech-time.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class SessionService {
|
|
|
|
constructor(private database: AngularFireDatabase,
|
|
private speechTimes: SpeechTimeService) { }
|
|
|
|
public addSession(sessionNumber: string, date: string, body: string | undefined): void {
|
|
if (body == null) {
|
|
console.error("body should not be undefined");
|
|
return;
|
|
}
|
|
const sessionRef = this.database.list<Session>('sessions');
|
|
sessionRef.push({
|
|
number: +sessionNumber,
|
|
date: date,
|
|
body: body
|
|
});
|
|
}
|
|
|
|
public deleteSession(sessionKey: string | null): void {
|
|
const sessionRef = this.database.list<Session>('sessions');
|
|
if (sessionKey != null) {
|
|
sessionRef.remove(sessionKey);
|
|
this.speechTimes.deleteSpeechTimes(sessionKey);
|
|
}
|
|
}
|
|
}
|