MCPcopy
hub / github.com/dev-mastery/comments-api / makeAddComment

Function makeAddComment

src/use-cases/add-comment.js:2–29  ·  view source on GitHub ↗
({ commentsDb, handleModeration })

Source from the content-addressed store, hash-verified

1import makeComment from '../comment'
2export 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}

Callers 2

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected