Skip to content

Commit

Permalink
Merge pull request #3909 from thematters/feat/article-drafts
Browse files Browse the repository at this point in the history
feat(draft): temporarily use article version as draft in article drafts API
  • Loading branch information
gary02 authored May 14, 2024
2 parents 8ca4d8b + e79f6f3 commit 920e3b8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
26 changes: 22 additions & 4 deletions src/queries/draft/article/drafts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import type { GQLArticleResolvers } from 'definitions'

const resolver: GQLArticleResolvers['drafts'] = async (
{ id: articleId },
{ id: articleId, authorId },
_,
{ dataSources: { atomService } }
) =>
atomService.findMany({
table: 'draft',
) => {
const versions = await atomService.findMany({
table: 'article_version',
where: { articleId },
orderBy: [{ column: 'created_at', order: 'desc' }],
})
return versions.map(async (version) => {
return {
...version,
authorId,
content: (
await atomService.articleContentIdLoader.load(version.contentId)
).content,
publishState: 'published',
// unused fields in front-end
contentMd: '',
iscnPublish: false,
collection: null,
remark: null,
archived: false,
language: null,
}
})
}

export default resolver
25 changes: 18 additions & 7 deletions src/queries/draft/article/newestPublishedDraft.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import type { GQLArticleResolvers } from 'definitions'

import { PUBLISH_STATE } from 'common/enums'

const resolver: GQLArticleResolvers['newestPublishedDraft'] = async (
{ id: articleId },
{ id: articleId, authorId },
_,
{ dataSources: { atomService } }
) => {
const draft = await atomService.findFirst({
table: 'draft',
where: { articleId, publishState: PUBLISH_STATE.published },
const version = await atomService.findFirst({
table: 'article_version',
where: { articleId },
orderBy: [{ column: 'created_at', order: 'desc' }],
})
return draft
return {
...version,
authorId,
content: (await atomService.articleContentIdLoader.load(version.contentId))
.content,
publishState: 'published',
// unused fields in front-end
contentMd: '',
iscnPublish: false,
collection: null,
remark: null,
archived: false,
language: null,
}
}

export default resolver

0 comments on commit 920e3b8

Please sign in to comment.