({ commentsDb, handleModeration })
| 1 | import makeComment from '../comment' |
| 2 | export default function makeAddComment ({ commentsDb, handleModeration }) { |
| 3 | return async function addComment (commentInfo) { |
| 4 | const comment = makeComment(commentInfo) |
| 5 | const exists = await commentsDb.findByHash({ hash: comment.getHash() }) |
| 6 | if (exists) { |
| 7 | return exists |
| 8 | } |
| 9 | |
| 10 | const moderated = await handleModeration({ comment }) |
| 11 | const commentSource = moderated.getSource() |
| 12 | return commentsDb.insert({ |
| 13 | author: moderated.getAuthor(), |
| 14 | createdOn: moderated.getCreatedOn(), |
| 15 | hash: moderated.getHash(), |
| 16 | id: moderated.getId(), |
| 17 | modifiedOn: moderated.getModifiedOn(), |
| 18 | postId: moderated.getPostId(), |
| 19 | published: moderated.isPublished(), |
| 20 | replyToId: moderated.getReplyToId(), |
| 21 | source: { |
| 22 | ip: commentSource.getIp(), |
| 23 | browser: commentSource.getBrowser(), |
| 24 | referrer: commentSource.getReferrer() |
| 25 | }, |
| 26 | text: moderated.getText() |
| 27 | }) |
| 28 | } |
| 29 | } |
no outgoing calls
no test coverage detected