Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions api/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand Down
1 change: 1 addition & 0 deletions api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down