|
1 | 1 | import type { z } from 'zod'
|
2 | 2 | import type { PlaylistAPIResponseModel, PlaylistModel } from '#modules/playlists/models'
|
| 3 | +import type { SearchPlaylistAPIResponseModel, SearchPlaylistModel } from '#modules/search/models' |
3 | 4 | import { createSongPayload } from '#modules/songs/helpers'
|
4 | 5 | import { createImageLinks } from '#common/helpers'
|
5 | 6 | import { createArtistMapPayload } from '#modules/artists/helpers'
|
6 | 7 |
|
7 | 8 | export const createPlaylistPayload = (
|
8 |
| - album: z.infer<typeof PlaylistAPIResponseModel> |
| 9 | + playlist: z.infer<typeof PlaylistAPIResponseModel> |
9 | 10 | ): z.infer<typeof PlaylistModel> => ({
|
10 |
| - id: album.id, |
11 |
| - name: album.title, |
12 |
| - description: album.header_desc, |
13 |
| - type: album.type, |
14 |
| - year: Number(album.year || 0), |
15 |
| - playCount: Number(album.play_count), |
16 |
| - language: album.language, |
17 |
| - explicitContent: album.explicit_content === '1', |
18 |
| - url: album.perma_url, |
19 |
| - songCount: Number(album.list_count || 0), |
20 |
| - artists: album.more_info.artists?.map(createArtistMapPayload), |
21 |
| - image: createImageLinks(album.image), |
22 |
| - ...(album.list && { songs: album.list.map((song) => createSongPayload(song)) }) |
| 11 | + id: playlist.id, |
| 12 | + name: playlist.title, |
| 13 | + description: playlist.header_desc, |
| 14 | + type: playlist.type, |
| 15 | + year: playlist.year ? Number(playlist.year) : null, |
| 16 | + playCount: playlist.play_count ? Number(playlist.play_count) : null, |
| 17 | + language: playlist.language, |
| 18 | + explicitContent: playlist.explicit_content === '1', |
| 19 | + url: playlist.perma_url, |
| 20 | + songCount: playlist.list_count ? Number(playlist.list_count) : null, |
| 21 | + artists: playlist.more_info.artists?.map(createArtistMapPayload) || null, |
| 22 | + image: createImageLinks(playlist.image), |
| 23 | + songs: (playlist.list && playlist.list?.map(createSongPayload)) || null |
| 24 | +}) |
| 25 | + |
| 26 | +export const createSearchPlaylistPayload = ( |
| 27 | + playlist: z.infer<typeof SearchPlaylistAPIResponseModel> |
| 28 | +): z.infer<typeof SearchPlaylistModel> => ({ |
| 29 | + total: Number(playlist.total), |
| 30 | + start: Number(playlist.start), |
| 31 | + results: playlist.results.map((item) => ({ |
| 32 | + id: item.id, |
| 33 | + name: item.title, |
| 34 | + type: item.type, |
| 35 | + image: createImageLinks(item.image), |
| 36 | + url: item.perma_url, |
| 37 | + songCount: item.more_info.song_count ? Number(item.more_info.song_count) : null, |
| 38 | + language: item.more_info.language, |
| 39 | + explicitContent: item.explicit_content === '1' |
| 40 | + })) |
23 | 41 | })
|
0 commit comments