Return 0 if looking up page reading progress fails

This commit is contained in:
Jackson Harper 2022-03-16 13:33:36 -07:00
parent 27143cbedf
commit dc27c0c7a4

View file

@ -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 },