-
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.
fix(edit-article): uniq tags & collection
- Loading branch information
Showing
4 changed files
with
19 additions
and
12 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 |
---|---|---|
|
@@ -241,7 +241,9 @@ class PublicationQueue extends BaseQueue { | |
if (tags && tags.length > 0) { | ||
// get tag editor | ||
const mattyUser = await this.userService.findByEmail('[email protected]') | ||
const tagEditors = [mattyUser.id, article.authorId] | ||
const tagEditors = mattyUser | ||
? [mattyUser.id, article.authorId] | ||
: [article.authorId] | ||
|
||
// create tag records, return tag record if already exists | ||
const dbTags = ((await Promise.all( | ||
|
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,4 +1,4 @@ | ||
import { difference } from 'lodash' | ||
import { difference, uniq } from 'lodash' | ||
|
||
import { ARTICLE_STATE, CACHE_KEYWORD, NODE_TYPES } from 'common/enums' | ||
import { | ||
|
@@ -94,16 +94,20 @@ const resolver: MutationToEditArticleResolver = async ( | |
if (tags) { | ||
// get tag editor | ||
const mattyUser = await userService.findByEmail('[email protected]') | ||
const tagEditors = [mattyUser.id, article.authorId] | ||
const tagEditors = mattyUser | ||
? [mattyUser.id, article.authorId] | ||
: [article.authorId] | ||
|
||
// create tag records | ||
const dbTags = ((await Promise.all( | ||
tags.map((tag: string) => | ||
tagService.create({ | ||
content: tag, | ||
creator: article.authorId, | ||
editors: tagEditors, | ||
}) | ||
uniq( | ||
tags.map((tag: string) => | ||
tagService.create({ | ||
content: tag, | ||
creator: article.authorId, | ||
editors: tagEditors, | ||
}) | ||
) | ||
) | ||
)) as unknown) as [{ id: string; content: string }] | ||
|
||
|
@@ -137,7 +141,9 @@ const resolver: MutationToEditArticleResolver = async ( | |
limit: null, | ||
}) | ||
).map(({ articleId }: { articleId: string }) => articleId) | ||
const newIds = collection.map((articleId) => fromGlobalId(articleId).id) | ||
const newIds = uniq( | ||
collection.map((articleId) => fromGlobalId(articleId).id) | ||
) | ||
const addItems: any[] = [] | ||
const updateItems: any[] = [] | ||
const diff = difference(newIds, oldIds) | ||
|
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
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