feat: add homepage components and API for settings and spielplan options
- 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.
This commit is contained in:
61
server/api/homepage/spielplan-options.get.js
Normal file
61
server/api/homepage/spielplan-options.get.js
Normal file
@@ -0,0 +1,61 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user