Merge pull request #2997 from omnivore-app/feature/reading-progress-api
ignore position check if force = true in reading progress api payload
This commit is contained in:
@ -2092,6 +2092,7 @@ export enum SaveArticleReadingProgressErrorCode {
|
||||
}
|
||||
|
||||
export type SaveArticleReadingProgressInput = {
|
||||
force?: InputMaybe<Scalars['Boolean']>;
|
||||
id: Scalars['ID'];
|
||||
readingProgressAnchorIndex?: InputMaybe<Scalars['Int']>;
|
||||
readingProgressPercent: Scalars['Float'];
|
||||
|
||||
@ -1571,6 +1571,7 @@ enum SaveArticleReadingProgressErrorCode {
|
||||
}
|
||||
|
||||
input SaveArticleReadingProgressInput {
|
||||
force: Boolean
|
||||
id: ID!
|
||||
readingProgressAnchorIndex: Int
|
||||
readingProgressPercent: Float!
|
||||
|
||||
@ -563,6 +563,7 @@ export const saveArticleReadingProgressResolver = authorized<
|
||||
readingProgressPercent,
|
||||
readingProgressAnchorIndex,
|
||||
readingProgressTopPercent,
|
||||
force,
|
||||
},
|
||||
},
|
||||
{ log, pubsub, uid }
|
||||
@ -578,6 +579,27 @@ export const saveArticleReadingProgressResolver = authorized<
|
||||
return { errorCodes: [SaveArticleReadingProgressErrorCode.BadData] }
|
||||
}
|
||||
try {
|
||||
if (force) {
|
||||
// update reading progress without checking the current value
|
||||
const updatedItem = await updateLibraryItem(
|
||||
id,
|
||||
{
|
||||
readingProgressBottomPercent: readingProgressPercent,
|
||||
readingProgressTopPercent: readingProgressTopPercent ?? undefined,
|
||||
readingProgressHighestReadAnchor:
|
||||
readingProgressAnchorIndex ?? undefined,
|
||||
readAt: new Date(),
|
||||
},
|
||||
uid,
|
||||
pubsub
|
||||
)
|
||||
|
||||
return {
|
||||
updatedArticle: libraryItemToArticle(updatedItem),
|
||||
}
|
||||
}
|
||||
|
||||
// update reading progress only if the current value is lower
|
||||
const updatedItem = await updateLibraryItemReadingProgress(
|
||||
id,
|
||||
uid,
|
||||
|
||||
@ -637,6 +637,7 @@ const schema = gql`
|
||||
readingProgressTopPercent: Float
|
||||
readingProgressPercent: Float!
|
||||
readingProgressAnchorIndex: Int
|
||||
force: Boolean
|
||||
}
|
||||
enum SaveArticleReadingProgressErrorCode {
|
||||
NOT_FOUND
|
||||
|
||||
@ -295,16 +295,18 @@ const setBookmarkQuery = (articleId: string, bookmark: boolean) => {
|
||||
const saveArticleReadingProgressQuery = (
|
||||
articleId: string,
|
||||
progress: number,
|
||||
topPercent: number | null = null
|
||||
topPercent: number | null = null,
|
||||
force: boolean | null = null
|
||||
) => {
|
||||
return `
|
||||
mutation {
|
||||
saveArticleReadingProgress(
|
||||
input: {
|
||||
id: "${articleId}",
|
||||
readingProgressPercent: ${progress}
|
||||
readingProgressAnchorIndex: 0
|
||||
readingProgressTopPercent: ${topPercent}
|
||||
readingProgressPercent: ${progress},
|
||||
readingProgressAnchorIndex: 0,
|
||||
readingProgressTopPercent: ${topPercent},
|
||||
force: ${force}
|
||||
}
|
||||
) {
|
||||
... on SaveArticleReadingProgressSuccess {
|
||||
@ -784,6 +786,37 @@ describe('Article API', () => {
|
||||
'BAD_DATA',
|
||||
])
|
||||
})
|
||||
|
||||
context('when force is true', () => {
|
||||
before(async () => {
|
||||
itemId = (await createLibraryItem({
|
||||
user: { id: user.id },
|
||||
originalUrl: 'https://blog.omnivore.app/setBookmarkArticle',
|
||||
slug: 'test-with-omnivore',
|
||||
readableContent: '<p>test</p>',
|
||||
title: 'test title',
|
||||
readingProgressBottomPercent: 100,
|
||||
readingProgressTopPercent: 80,
|
||||
}, user.id)).id
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await deleteLibraryItemById(itemId, user.id)
|
||||
})
|
||||
|
||||
it('ignore position check if force is true', async () => {
|
||||
query = saveArticleReadingProgressQuery(itemId, 20, 10, true)
|
||||
const res = await graphqlRequest(query, authToken).expect(200)
|
||||
expect(
|
||||
res.body.data.saveArticleReadingProgress.updatedArticle
|
||||
.readingProgressPercent
|
||||
).to.eql(20)
|
||||
expect(
|
||||
res.body.data.saveArticleReadingProgress.updatedArticle
|
||||
.readingProgressTopPercent
|
||||
).to.eql(10)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('SaveFile', () => {
|
||||
|
||||
Reference in New Issue
Block a user