Skip to content

Commit

Permalink
fix(edit-article): uniq tags & collection
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Jul 8, 2020
1 parent 673b5bb commit 9d3d39d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/connectors/queue/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 15 additions & 9 deletions src/mutations/article/editArticle.ts
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 {
Expand Down Expand Up @@ -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 }]

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/queries/article/tag/editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const resolver: TagToEditorsResolver = (
{ editors },
_,
{ dataSources: { userService } }
) => userService.dataloader.loadMany(editors)
) => userService.dataloader.loadMany(editors || [])

export default resolver
1 change: 0 additions & 1 deletion src/types/directives/purgeCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class PurgeCacheDirective extends SchemaDirectiveVisitor {
const [root, _, { redis }, { returnType }] = args

const result = await resolve.apply(this, args)

if (result && result.id && redis && returnType) {
try {
const cache = _get(result, CACHE_KEYWORD, [])
Expand Down

0 comments on commit 9d3d39d

Please sign in to comment.