Merge pull request #249 from omnivore-app/fix/elastic-reading-progress-nulls

Fix/elastic reading progress nulls
This commit is contained in:
Jackson Harper 2022-03-16 14:35:45 -07:00 committed by GitHub
commit 46f9306e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -386,6 +386,47 @@ 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
}
console.log(
'looking up reading progress for article',
article.id,
article
)
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 },