-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3909 from thematters/feat/article-drafts
feat(draft): temporarily use article version as draft in article drafts API
- Loading branch information
Showing
2 changed files
with
40 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |