diff --git a/api/listeners.js b/api/listeners.js index 33a26fa..6233d8c 100644 --- a/api/listeners.js +++ b/api/listeners.js @@ -16,17 +16,32 @@ router.get("/", authenticateJWT, async (req, res) => { include: [ { model: User, - // as: "user", - attributes: ["spotify_display_name", "spotify_image"], + attributes: ["id", "username", "spotify_display_name", "spotify_image"], }, { model: Song, - // as: "track", - attributes: ["id", "title", "artist", "album_art", "album"] - }], + attributes: ["id", "title", "artist", "album_art", "album", "spotify_track_id"] + } + ], order: [["updated_at", "DESC"]] }); - res.json(sessions) + + // Format the response to match the required structure + const formatted = sessions.map(session => ({ + user: { + id: session.user?.id, + username: session.user?.username, + spotify_display_name: session.user?.spotify_display_name, + spotify_image: session.user?.spotify_image, + }, + song: session.song ? { + title: session.song.title, + artist: session.song.artist, + album_art: session.song.album_art, + spotify_track_id: session.song.spotify_track_id, + } : null + })); + res.json(formatted); } catch (error) { console.log("failed to fetch all listening sessions") res.status(500).json({ error: "Failed to get all listening sessions" }) diff --git a/api/users.js b/api/users.js index 4b11610..3445ca0 100644 --- a/api/users.js +++ b/api/users.js @@ -44,6 +44,7 @@ router.get("/online", authenticateJWT, async (req, res) => { const coords = extractLatLng(u.location); if (!coords) continue; // skip malformed locations mapped.push({ + id: u.id, username: u.username, latitude: coords.latitude, longitude: coords.longitude,