A decentralized music tracking and discovery platform built on AT Protocol 🎵

Include artist genres in scrobbles response

+20 -15
+20 -15
apps/api/src/xrpc/app/rocksky/scrobble/getScrobbles.ts
··· 10 10 import type { SelectScrobble } from "schema/scrobbles"; 11 11 import type { SelectTrack } from "schema/tracks"; 12 12 import type { SelectUser } from "schema/users"; 13 + import { SelectArtist } from "schema/artists"; 13 14 14 15 export default function (server: Server, ctx: Context) { 15 16 const getScrobbles = (params: QueryParams) => ··· 83 84 .select() 84 85 .from(tables.scrobbles) 85 86 .leftJoin(tables.tracks, eq(tables.scrobbles.trackId, tables.tracks.id)) 86 - .leftJoin(tables.users, eq(tables.scrobbles.userId, tables.users.id)); 87 + .leftJoin(tables.users, eq(tables.scrobbles.userId, tables.users.id)) 88 + .leftJoin(tables.artists, eq(tables.scrobbles.artistId, tables.artists.id)); 87 89 88 90 const query = filterDids 89 91 ? baseQuery.where(inArray(tables.users.did, filterDids)) ··· 137 139 data: Scrobbles, 138 140 ): Effect.Effect<{ scrobbles: ScrobbleViewBasic[] }, never> => { 139 141 return Effect.sync(() => ({ 140 - scrobbles: data.map(({ scrobbles, tracks, users, liked, likesCount }) => ({ 141 - ...R.omit(["albumArt", "id", "lyrics"])(tracks), 142 - cover: tracks.albumArt, 143 - date: scrobbles.timestamp.toISOString(), 144 - user: users.handle, 145 - userDisplayName: users.displayName, 146 - userAvatar: users.avatar, 147 - uri: scrobbles.uri, 148 - tags: [], 149 - id: scrobbles.id, 150 - trackUri: tracks.uri, 151 - likesCount, 152 - liked, 153 - })), 142 + scrobbles: data.map( 143 + ({ scrobbles, tracks, users, artists, liked, likesCount }) => ({ 144 + ...R.omit(["albumArt", "id", "lyrics"])(tracks), 145 + cover: tracks.albumArt, 146 + date: scrobbles.timestamp.toISOString(), 147 + user: users.handle, 148 + userDisplayName: users.displayName, 149 + userAvatar: users.avatar, 150 + uri: scrobbles.uri, 151 + tags: artists?.genres, 152 + id: scrobbles.id, 153 + trackUri: tracks.uri, 154 + likesCount, 155 + liked, 156 + }), 157 + ), 154 158 })); 155 159 }; 156 160 ··· 158 162 scrobbles: SelectScrobble; 159 163 tracks: SelectTrack; 160 164 users: SelectUser; 165 + artists: SelectArtist; 161 166 liked: boolean; 162 167 likesCount: number; 163 168 }[];