make readingProgress required in the elastic page data (#253)

* make readingProgress required in the elastic page data

* delete readingProgress from function_resolvers because we have stored them in elastic
This commit is contained in:
Hongbo Wu
2022-03-17 10:06:21 +08:00
committed by GitHub
parent 46f9306e17
commit af037a2837
10 changed files with 17 additions and 43 deletions

View File

@ -166,6 +166,7 @@ export const createPage = async (
...page,
updatedAt: new Date(),
createdAt: new Date(),
savedAt: new Date(),
},
refresh: ctx.refresh,
})

View File

@ -132,8 +132,8 @@ export interface Page {
originalHtml?: string | null
slug: string
labels?: Label[]
readingProgressPercent?: number
readingProgressAnchorIndex?: number
readingProgressPercent: number
readingProgressAnchorIndex: number
createdAt: Date
updatedAt?: Date
publishedAt?: Date

View File

@ -272,6 +272,8 @@ export const createArticleResolver = authorized<
createdAt: saveTime,
savedAt: saveTime,
siteName: parsedContent?.siteName,
readingProgressPercent: 0,
readingProgressAnchorIndex: 0,
}
let archive = false

View File

@ -386,47 +386,6 @@ 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 },

View File

@ -155,6 +155,8 @@ export function pdfAttachmentsRouter() {
slug: generateSlug(title),
id: '',
createdAt: new Date(),
readingProgressPercent: 0,
readingProgressAnchorIndex: 0,
}
const pageId = await createPage(articleToSave, {

View File

@ -63,6 +63,8 @@ export const saveEmail = async (
publishedAt: validatedDate(parseResult.parsedContent?.publishedDate),
slug: slug,
createdAt: new Date(),
readingProgressAnchorIndex: 0,
readingProgressPercent: 0,
}
const page = await getPageByParam({ url: articleToSave.url })

View File

@ -106,6 +106,8 @@ export const saveFile = async (
userId: saver.id,
id: '',
createdAt: new Date(),
readingProgressPercent: 0,
readingProgressAnchorIndex: 0,
},
ctx
)

View File

@ -101,6 +101,8 @@ export const savePage = async (
image: parseResult.parsedContent?.previewImage,
publishedAt: validatedDate(parseResult.parsedContent?.publishedDate),
createdAt: new Date(),
readingProgressPercent: 0,
readingProgressAnchorIndex: 0,
}
const existingPage = await getPageByParam({

View File

@ -571,6 +571,8 @@ describe('Article API', () => {
createdAt: new Date(),
url: 'https://blog.omnivore.app/setBookmarkArticle',
slug: 'test-with-omnivore',
readingProgressPercent: 0,
readingProgressAnchorIndex: 0,
}
const newPageId = await createPage(page, ctx)
if (newPageId) {

View File

@ -50,6 +50,8 @@ export const createTestElasticPage = async (
url: 'https://example.com/test-url',
slug: 'test-with-omnivore',
labels: labels,
readingProgressPercent: 0,
readingProgressAnchorIndex: 0,
}
const pageId = await createPage(page, {