refactor: improve typing in backend (#748)

This commit is contained in:
Carlos Valente
2024-01-30 21:12:19 +01:00
committed by GitHub
parent 39711c1edd
commit 6a5020424b
26 changed files with 703 additions and 147 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ class Logger {
* @param origin
* @param text
*/
emit(level, origin: string, text: string) {
emit(level: LogLevel, origin: string, text: string) {
const log = {
id: generateId(),
level,
@@ -74,12 +74,12 @@ export class EventLoader {
// if there is no event running, go to first
if (!currentEventId) {
return timedEvents.at(0);
return timedEvents.at(0) ?? null;
}
const currentIndex = timedEvents.findIndex((event) => event.id === currentEventId);
const newIndex = Math.max(currentIndex - 1, 0);
const previousEvent = timedEvents.at(newIndex);
const previousEvent = timedEvents.at(newIndex) ?? null;
return previousEvent;
}
@@ -95,12 +95,12 @@ export class EventLoader {
// if there is no event running, go to first
if (!currentEventId) {
return timedEvents.at(0);
return timedEvents.at(0) ?? null;
}
const currentIndex = timedEvents.findIndex((event) => event.id === currentEventId);
const newIndex = (currentIndex + 1) % timedEvents.length;
const nextEvent = timedEvents.at(newIndex);
return nextEvent;
return nextEvent ?? null;
}
}