Some checks failed
Code Analysis and Production Deploy / analyze (push) Has been skipped
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Successful in 1m49s
Code Analysis and Production Deploy / analyze (pull_request) Failing after 2m37s
Code Analysis and Production Deploy / deploy-production (pull_request) Has been skipped
Code Analysis and Production Deploy / deploy-test (pull_request) Has been skipped
Require Package Version Change / check (pull_request) Failing after 8s
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import { listSpielplanSeasons, readSpielplanData, validateSeasonSlug } from '../utils/spielplan-data.js'
|
|
import { error as loggerError } from '../utils/logger.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const query = getQuery(event)
|
|
if (query.season && !validateSeasonSlug(query.season)) {
|
|
loggerError('Ungueltiger Saison-Slug angefragt', { season: query.season })
|
|
return {
|
|
success: false,
|
|
message: 'Ungueltiger Saison-Slug',
|
|
data: [],
|
|
headers: []
|
|
}
|
|
}
|
|
const [spielplan, seasons] = await Promise.all([
|
|
readSpielplanData({ season: query.season }),
|
|
listSpielplanSeasons()
|
|
])
|
|
|
|
if (!spielplan.data.length || !spielplan.headers.length) {
|
|
return {
|
|
success: false,
|
|
message: 'Spielplan-Datei nicht gefunden oder leer',
|
|
data: [],
|
|
headers: []
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
message: 'Spielplan erfolgreich geladen',
|
|
data: spielplan.data,
|
|
headers: spielplan.headers,
|
|
source: spielplan.source,
|
|
filePath: spielplan.filePath,
|
|
season: spielplan.season,
|
|
seasons
|
|
}
|
|
} catch (error) {
|
|
loggerError('Fehler beim Laden des Spielplans:', { error })
|
|
return {
|
|
success: false,
|
|
message: 'Fehler beim Laden des Spielplans',
|
|
data: [],
|
|
headers: []
|
|
}
|
|
}
|
|
})
|