From 3467ba3cbce5f3926ebf886de95da0dbc3e3adcd Mon Sep 17 00:00:00 2001 From: Sumit Kolhe <35036894+sumitkolhe@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:31:22 +0530 Subject: [PATCH] fix: make song fields nullable --- src/modules/songs/helpers/song.helper.ts | 16 ++++++++-------- src/modules/songs/models/song.model.ts | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/modules/songs/helpers/song.helper.ts b/src/modules/songs/helpers/song.helper.ts index 5176ec4c..d748497a 100644 --- a/src/modules/songs/helpers/song.helper.ts +++ b/src/modules/songs/helpers/song.helper.ts @@ -7,21 +7,21 @@ export const createSongPayload = (song: z.infer): z id: song.id, name: song.title, type: song.type, - year: Number(song.year || 0), - releaseDate: song.more_info?.release_date, - duration: Number(song.more_info?.duration), - label: song.more_info?.label, + year: song?.year || null, + releaseDate: song.more_info?.release_date || null, + duration: song.more_info?.duration ? Number(song.more_info?.duration) : null, + label: song.more_info?.label || null, explicitContent: song.explicit_content === '1', playCount: Number(song.play_count || 0), language: song.language, hasLyrics: song.more_info?.has_lyrics === 'true', lyricsId: song.more_info?.lyrics_id || null, url: song.perma_url, - copyright: song.more_info?.copyright_text, + copyright: song.more_info?.copyright_text || null, album: { - id: song.more_info?.album_id, - name: song.more_info?.album, - url: song.more_info?.album_url + id: song.more_info?.album_id || null, + name: song.more_info?.album || null, + url: song.more_info?.album_url || null }, artists: { primary: song.more_info?.artistMap?.primary_artists?.map(createArtistMapPayload), diff --git a/src/modules/songs/models/song.model.ts b/src/modules/songs/models/song.model.ts index 34b993c5..405f64c1 100644 --- a/src/modules/songs/models/song.model.ts +++ b/src/modules/songs/models/song.model.ts @@ -12,7 +12,7 @@ export const SongAPIResponseModel = z.object({ perma_url: z.string(), image: z.string(), language: z.string(), - year: z.number(), + year: z.string(), play_count: z.string(), explicit_content: z.string(), list_count: z.string(), @@ -61,10 +61,10 @@ export const SongModel = z.object({ id: z.string(), name: z.string(), type: z.string(), - year: z.number(), - releaseDate: z.string(), - duration: z.number(), - label: z.string(), + year: z.string().nullable(), + releaseDate: z.string().nullable(), + duration: z.number().nullable(), + label: z.string().nullable(), explicitContent: z.boolean(), playCount: z.number(), language: z.string(), @@ -72,11 +72,11 @@ export const SongModel = z.object({ lyricsId: z.string().nullable(), lyrics: LyricsModel.optional(), url: z.string(), - copyright: z.string(), + copyright: z.string().nullable(), album: z.object({ - id: z.string(), - name: z.string(), - url: z.string() + id: z.string().nullable(), + name: z.string().nullable(), + url: z.string().nullable() }), artists: z.object({ primary: z.array(ArtistMapModel),