Skip to content

Commit 3467ba3

Browse files
committed
fix: make song fields nullable
1 parent 4787ce9 commit 3467ba3

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/modules/songs/helpers/song.helper.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ export const createSongPayload = (song: z.infer<typeof SongAPIResponseModel>): z
77
id: song.id,
88
name: song.title,
99
type: song.type,
10-
year: Number(song.year || 0),
11-
releaseDate: song.more_info?.release_date,
12-
duration: Number(song.more_info?.duration),
13-
label: song.more_info?.label,
10+
year: song?.year || null,
11+
releaseDate: song.more_info?.release_date || null,
12+
duration: song.more_info?.duration ? Number(song.more_info?.duration) : null,
13+
label: song.more_info?.label || null,
1414
explicitContent: song.explicit_content === '1',
1515
playCount: Number(song.play_count || 0),
1616
language: song.language,
1717
hasLyrics: song.more_info?.has_lyrics === 'true',
1818
lyricsId: song.more_info?.lyrics_id || null,
1919
url: song.perma_url,
20-
copyright: song.more_info?.copyright_text,
20+
copyright: song.more_info?.copyright_text || null,
2121
album: {
22-
id: song.more_info?.album_id,
23-
name: song.more_info?.album,
24-
url: song.more_info?.album_url
22+
id: song.more_info?.album_id || null,
23+
name: song.more_info?.album || null,
24+
url: song.more_info?.album_url || null
2525
},
2626
artists: {
2727
primary: song.more_info?.artistMap?.primary_artists?.map(createArtistMapPayload),

src/modules/songs/models/song.model.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const SongAPIResponseModel = z.object({
1212
perma_url: z.string(),
1313
image: z.string(),
1414
language: z.string(),
15-
year: z.number(),
15+
year: z.string(),
1616
play_count: z.string(),
1717
explicit_content: z.string(),
1818
list_count: z.string(),
@@ -61,22 +61,22 @@ export const SongModel = z.object({
6161
id: z.string(),
6262
name: z.string(),
6363
type: z.string(),
64-
year: z.number(),
65-
releaseDate: z.string(),
66-
duration: z.number(),
67-
label: z.string(),
64+
year: z.string().nullable(),
65+
releaseDate: z.string().nullable(),
66+
duration: z.number().nullable(),
67+
label: z.string().nullable(),
6868
explicitContent: z.boolean(),
6969
playCount: z.number(),
7070
language: z.string(),
7171
hasLyrics: z.boolean(),
7272
lyricsId: z.string().nullable(),
7373
lyrics: LyricsModel.optional(),
7474
url: z.string(),
75-
copyright: z.string(),
75+
copyright: z.string().nullable(),
7676
album: z.object({
77-
id: z.string(),
78-
name: z.string(),
79-
url: z.string()
77+
id: z.string().nullable(),
78+
name: z.string().nullable(),
79+
url: z.string().nullable()
8080
}),
8181
artists: z.object({
8282
primary: z.array(ArtistMapModel),

0 commit comments

Comments
 (0)