mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Update post factories with guard clause
This commit is contained in:
parent
b48b93dd0d
commit
d6a5b7ce65
@ -53,17 +53,18 @@ export default function create() {
|
|||||||
|
|
||||||
const post = await neodeInstance.create('Post', args)
|
const post = await neodeInstance.create('Post', args)
|
||||||
|
|
||||||
let { comment, commentContent } = args
|
const { commentContent } = args
|
||||||
delete args.comment
|
let comment
|
||||||
delete args.commentContent
|
delete args.commentContent
|
||||||
if (comment && commentContent) throw new Error('You provided both comment and commentContent')
|
if (commentContent)
|
||||||
if (commentContent) comment = await neodeInstance.find('Comment', commentContent)
|
comment = await factoryInstance.create('Comment', {
|
||||||
comment =
|
contentExcerpt: commentContent,
|
||||||
comment ||
|
post,
|
||||||
(await factoryInstance.create('Comment', { content: commentContent, post, author }))
|
author,
|
||||||
|
})
|
||||||
|
|
||||||
await post.relateTo(author, 'author')
|
await post.relateTo(author, 'author')
|
||||||
await post.relateTo(comment, 'comments')
|
if (comment) await post.relateTo(comment, 'comments')
|
||||||
await Promise.all(categories.map(c => c.relateTo(post, 'post')))
|
await Promise.all(categories.map(c => c.relateTo(post, 'post')))
|
||||||
await Promise.all(tags.map(t => t.relateTo(post, 'post')))
|
await Promise.all(tags.map(t => t.relateTo(post, 'post')))
|
||||||
return post
|
return post
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user