Delete highlights, labels and other metadata when soft delete pages

This commit is contained in:
Hongbo Wu 2022-10-20 11:16:49 +08:00
parent 77327d1929
commit e1de55bea0
2 changed files with 19 additions and 4 deletions

View file

@ -437,11 +437,19 @@ export const getArticleResolver: ResolverFn<
// We allow the backend to use the ID instead of a slug to fetch the article
const page =
(await getPageByParam(
{ userId: claims.uid, slug },
{
userId: claims.uid,
slug,
state: ArticleSavingRequestStatus.Succeeded,
},
includeOriginalHtml
)) ||
(await getPageByParam(
{ userId: claims.uid, _id: slug },
{
userId: claims.uid,
_id: slug,
state: ArticleSavingRequestStatus.Succeeded,
},
includeOriginalHtml
))
@ -643,10 +651,16 @@ export const setBookmarkArticleResolver = authorized<
return { errorCodes: [SetBookmarkArticleErrorCode.NotFound] }
}
// delete the page
// delete the page and its metadata
const deleted = await updatePage(
pageRemoved.id,
{ state: ArticleSavingRequestStatus.Deleted },
{
state: ArticleSavingRequestStatus.Deleted,
labels: [],
highlights: [],
readingProgressAnchorIndex: 0,
readingProgressPercent: 0,
},
{ pubsub, uid }
)
if (!deleted) {

View file

@ -688,6 +688,7 @@ describe('Article API', () => {
await graphqlRequest(query, authToken).expect(200)
const page = await getPageById(articleId)
expect(page?.state).to.eql(ArticleSavingRequestStatus.Deleted)
expect(page?.highlights).to.eql([])
})
})
})