Split Album into AlbumSummary and Album as per Artist

This commit is contained in:
simojenki
2021-03-06 08:51:31 +11:00
parent 5c75a3d50b
commit 5f9c240cdf
5 changed files with 48 additions and 26 deletions

View File

@@ -14,6 +14,8 @@ import {
slice2,
asResult,
ArtistSummary,
Album,
AlbumSummary
} from "../src/music_service";
export const artistToArtistSummary = (
@@ -24,6 +26,15 @@ export const artistToArtistSummary = (
image: it.image,
});
export const albumToAlbumSummary = (
it: Album
): AlbumSummary => ({
id: it.id,
name: it.name,
year: it.year,
genre: it.genre,
});
type P<T> = (t: T) => boolean;
const all: P<any> = (_: any) => true;
const artistWithId = (id: string): P<Artist> => (artist: Artist) =>
@@ -79,8 +90,10 @@ export class InMemoryMusicService implements MusicService {
)
)
.then((artists) => artists.flatMap((it) => it.albums))
.then(it => it.map(albumToAlbumSummary))
.then(slice2(q))
.then(asResult),
// album: (id: albumId) => Promise.resolve(this.artists.flatMap(it => it.albums).find(it => it.id === id))
});
}