Nandrx fdffc08417 Improve code quality, security, and accessibility
- Fix login check: use HTTP 200 instead of 201 for GET /api/user
- Add encodeURIComponent for city in Ticketmaster URL
- Re-throw errors in ticketmaster.js so app.js can show user feedback
- Add JSDoc comments to all service and utility modules
- Add German labels and text throughout (de-CH locale)
2026-05-31 17:48:39 +02:00

29 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* eventService.js Transformiert rohe Ticketmaster-API-Daten in ein vereinfachtes Event-Objekt.
* Kapselt die Datenstruktur der externen API, sodass der Rest der App davon unabhängig bleibt.
*/
import { fetchEvents } from "../api/ticketmaster.js";
/**
* Lädt und transformiert Events für eine gegebene Stadt.
* @param {string} city - Stadtname
* @returns {Promise<Array<{id, name, date, time, venue, category}>>}
*/
export async function getEvents(city) {
const events = await fetchEvents(city);
// Rohe API-Daten auf ein einheitliches, einfaches Format abbilden
return events.map(event => ({
id: event.id,
name: event.name,
date: event.dates?.start?.localDate || null,
time: event.dates?.start?.localTime || null,
venue: event._embedded?.venues?.[0]?.name || "Unbekannter Ort",
// Kategorie aus dem ersten Klassifizierungs-Segment extrahieren (z.B. "Music", "Sports")
category: event.classifications?.[0]?.segment?.name
? event.classifications[0].segment.name.toLowerCase()
: null
}));
}