From 8cc283182721e007c644ea4c9eac25d6890a2cd5 Mon Sep 17 00:00:00 2001 From: veryCrunchy Date: Sun, 19 May 2024 17:40:21 +0200 Subject: [PATCH] fix(watchtime): handle null data --- src/gql/resolvers/watchtime.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gql/resolvers/watchtime.ts b/src/gql/resolvers/watchtime.ts index e233f69..556032e 100644 --- a/src/gql/resolvers/watchtime.ts +++ b/src/gql/resolvers/watchtime.ts @@ -75,14 +75,18 @@ const watchtimeResolver: Resolvers["Query"] = { display_name: string; profile_image_url: string; }[]; - return times.map(entry => { - const data = userData.find(user => user.id === entry.id); - return { - displayName: data!.display_name, - time: entry.time ?? 0, - avatar: data!.profile_image_url, - }; - }); + return times + .map(entry => { + const data = userData.find(user => user.id === entry.id); + if (!data) return null; + + return { + displayName: data.display_name, + time: entry.time ?? 0, + avatar: data.profile_image_url, + }; + }) + .filter(e => e !== null); }, }; export default watchtimeResolver;