From 4787ce9f92a7c0f5dcacfe82e4e52355c2685c80 Mon Sep 17 00:00:00 2001 From: Sumit Kolhe <35036894+sumitkolhe@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:30:40 +0530 Subject: [PATCH] fix: make artist fields nullable --- src/modules/artists/helpers/artist.helper.ts | 38 ++++----- src/modules/artists/models/artist.model.ts | 83 ++++++++++++-------- 2 files changed, 69 insertions(+), 52 deletions(-) diff --git a/src/modules/artists/helpers/artist.helper.ts b/src/modules/artists/helpers/artist.helper.ts index 1c1ae838..0c0f320f 100644 --- a/src/modules/artists/helpers/artist.helper.ts +++ b/src/modules/artists/helpers/artist.helper.ts @@ -14,29 +14,29 @@ export const createArtistPayload = (artist: z.infer<typeof ArtistAPIResponseMode name: artist.name, url: artist.urls?.overview || artist.perma_url, type: artist.type, - followerCount: Number(artist.follower_count), - fanCount: artist.fan_count, - isVerified: artist.isVerified, - dominantLanguage: artist.dominantLanguage, - dominantType: artist.dominantType, - bio: artist.bio && JSON.parse(artist.bio), - dob: artist.dob, - fb: artist.fb, - twitter: artist.twitter, - wiki: artist.wiki, - availableLanguages: artist.availableLanguages, - isRadioPresent: artist.isRadioPresent, + followerCount: artist.follower_count ? Number(artist.follower_count) : null, + fanCount: artist.fan_count || null, + isVerified: artist.isVerified || null, + dominantLanguage: artist.dominantLanguage || null, + dominantType: artist.dominantType || null, + bio: artist.bio ? JSON.parse(artist.bio) : null, + dob: artist.dob || null, + fb: artist.fb || null, + twitter: artist.twitter || null, + wiki: artist.wiki || null, + availableLanguages: artist.availableLanguages || null, + isRadioPresent: artist.isRadioPresent || null, image: createImageLinks(artist.image), - topSongs: artist.topSongs?.map(createSongPayload) || [], - topAlbums: artist.topAlbums?.map(createAlbumPayload) || [], - singles: artist.singles?.map(createSongPayload) || [], + topSongs: artist.topSongs?.map(createSongPayload) || null, + topAlbums: artist.topAlbums?.map(createAlbumPayload) || null, + singles: artist.singles?.map(createSongPayload) || null, similarArtists: artist.similarArtists?.map((similarArtist) => ({ id: similarArtist.id, name: similarArtist.name, url: similarArtist.perma_url, image: createImageLinks(similarArtist.image_url), - languages: similarArtist.languages && JSON.parse(similarArtist.languages), + languages: similarArtist.languages ? JSON.parse(similarArtist.languages) : null, wiki: similarArtist.wiki, dob: similarArtist.dob, fb: similarArtist.fb, @@ -45,9 +45,9 @@ export const createArtistPayload = (artist: z.infer<typeof ArtistAPIResponseMode type: similarArtist.type, dominantType: similarArtist.dominantType, aka: similarArtist.aka, - bio: similarArtist.bio, - similarArtists: similarArtist.similar && JSON.parse(similarArtist.similar) - })) || [] + bio: similarArtist.bio ? JSON.parse(similarArtist.bio) : null, + similarArtists: similarArtist.similar ? JSON.parse(similarArtist.similar) : null + })) || null }) export const createArtistMapPayload = ( diff --git a/src/modules/artists/models/artist.model.ts b/src/modules/artists/models/artist.model.ts index 934ff2e2..29db2199 100644 --- a/src/modules/artists/models/artist.model.ts +++ b/src/modules/artists/models/artist.model.ts @@ -128,38 +128,55 @@ export const ArtistModel = z.object({ url: z.string(), type: z.string(), image: z.array(DownloadLinkModel), - followerCount: z.number(), - fanCount: z.string(), - isVerified: z.boolean(), - dominantLanguage: z.string(), - dominantType: z.string(), - bio: z.string(), - dob: z.string(), - fb: z.string(), - twitter: z.string(), - wiki: z.string(), + followerCount: z.number().nullable(), + fanCount: z.string().nullable(), + isVerified: z.boolean().nullable(), + dominantLanguage: z.string().nullable(), + dominantType: z.string().nullable(), + bio: z + .array( + z.object({ + text: z.string().nullable(), + title: z.string().nullable(), + sequence: z.number().nullable() + }) + ) + .nullable(), + dob: z.string().nullable(), + fb: z.string().nullable(), + twitter: z.string().nullable(), + wiki: z.string().nullable(), availableLanguages: z.array(z.string()), - isRadioPresent: z.boolean(), - topSongs: z.array(SongModel), - topAlbums: z.array(AlbumModel), - singles: z.array(SongModel), - similarArtists: z.array( - z.object({ - id: z.string(), - name: z.string(), - url: z.string(), - image: z.array(DownloadLinkModel), - languages: z.string(), - wiki: z.string(), - dob: z.string(), - fb: z.string(), - twitter: z.string(), - isRadioPresent: z.boolean(), - type: z.string(), - dominantType: z.string(), - aka: z.string(), - bio: z.string(), - similarArtists: z.string() - }) - ) + isRadioPresent: z.boolean().nullable(), + topSongs: z.array(SongModel).nullable(), + topAlbums: z.array(AlbumModel).nullable(), + singles: z.array(SongModel).nullable(), + similarArtists: z + .array( + z.object({ + id: z.string(), + name: z.string(), + url: z.string(), + image: z.array(DownloadLinkModel), + languages: z.record(z.string(), z.string()).nullable(), + wiki: z.string(), + dob: z.string(), + fb: z.string(), + twitter: z.string(), + isRadioPresent: z.boolean(), + type: z.string(), + dominantType: z.string(), + aka: z.string(), + bio: z.string().nullable(), + similarArtists: z + .array( + z.object({ + id: z.string(), + name: z.string() + }) + ) + .nullable() + }) + ) + .nullable() })