From dc27c0c7a4ea61f1570f31191e2e963a42e6212f Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 16 Mar 2022 13:33:36 -0700 Subject: [PATCH] Return 0 if looking up page reading progress fails --- .../api/src/resolvers/function_resolvers.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/api/src/resolvers/function_resolvers.ts b/packages/api/src/resolvers/function_resolvers.ts index 1ee95e46c..c53fce576 100644 --- a/packages/api/src/resolvers/function_resolvers.ts +++ b/packages/api/src/resolvers/function_resolvers.ts @@ -386,6 +386,38 @@ export const functionResolvers = { ? ContentReader.Pdf : ContentReader.Web }, + async readingProgressPercent( + article: { id: string; readingProgressPercent?: number }, + _: unknown, + ctx: WithDataSourcesContext & { claims: Claims } + ) { + // != used here to check for null or undefined + if (article.readingProgressPercent != null) { + return article.readingProgressPercent + } + return ( + await getPageByParam({ + userId: ctx.claims.uid, + _id: article.id, + }) + )?.readingProgressPercent || 0 + }, + async readingProgressAnchorIndex( + article: { id: string; readingProgressAnchorIndex?: number }, + _: unknown, + ctx: WithDataSourcesContext & { claims: Claims } + ) { + // != used here to check for null or undefined + if (article.readingProgressAnchorIndex != null) { + return article.readingProgressAnchorIndex + } + return ( + await getPageByParam({ + userId: ctx.claims.uid, + _id: article.id, + }) + )?.readingProgressAnchorIndex || 0 + }, async highlights( article: { id: string; userId?: string }, _: { input: ArticleHighlightsInput },