- Introduced new Vue components for homepage teasers: HomeLinksTeaser, HomeSpielplanTeamWidget, HomeTrainingTeaser, and HomeVereinsmeisterschaftenTeaser. - Created XML layout for tablet app window dump. - Implemented API endpoints for fetching and updating homepage settings. - Added API for retrieving spielplan options, including team extraction logic.
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import { listSpielplanSeasons, readSpielplanData, validateSeasonSlug } from '../../utils/spielplan-data.js'
|
|
|
|
function teamLabel(teamName, teamAgeGroup) {
|
|
const name = String(teamName || '').trim()
|
|
const age = String(teamAgeGroup || '').trim()
|
|
if (!name) return ''
|
|
const isYouth = age.toLowerCase().includes('jugend') || name.toLowerCase().includes('jugend')
|
|
return isYouth ? `(J) ${name}` : name
|
|
}
|
|
|
|
function extractHarheimerTeams(rows) {
|
|
const seen = new Set()
|
|
const teams = []
|
|
|
|
const addTeam = (teamName, teamAgeGroup) => {
|
|
const name = String(teamName || '').trim()
|
|
if (!name) return
|
|
const age = String(teamAgeGroup || '').trim()
|
|
const key = `${name}||${age}`
|
|
if (seen.has(key)) return
|
|
seen.add(key)
|
|
teams.push({
|
|
key,
|
|
label: teamLabel(name, age),
|
|
teamName: name,
|
|
teamAgeGroup: age
|
|
})
|
|
}
|
|
|
|
for (const row of rows || []) {
|
|
if (String(row.HeimVereinName || '').trim() === 'Harheimer TC') {
|
|
addTeam(row.HeimMannschaft, row.HeimMannschaftAltersklasse)
|
|
}
|
|
if (String(row.GastVereinName || '').trim() === 'Harheimer TC') {
|
|
addTeam(row.GastMannschaft, row.GastMannschaftAltersklasse)
|
|
}
|
|
}
|
|
|
|
return teams.sort((a, b) => a.label.localeCompare(b.label, 'de'))
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const query = getQuery(event)
|
|
if (query.season && !validateSeasonSlug(query.season)) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: 'Ungültiger Saison-Slug.'
|
|
})
|
|
}
|
|
|
|
const seasons = await listSpielplanSeasons()
|
|
const selectedSeason = String(query.season || seasons[0]?.slug || '')
|
|
const dataResult = await readSpielplanData(selectedSeason ? { season: selectedSeason } : {})
|
|
|
|
return {
|
|
success: true,
|
|
selectedSeason,
|
|
seasons,
|
|
teams: extractHarheimerTeams(dataResult.data)
|
|
}
|
|
}) |