({ postId, omitReplies = true })
| 31 | return { id, ...info } |
| 32 | } |
| 33 | async function findByPostId ({ postId, omitReplies = true }) { |
| 34 | const db = await makeDb() |
| 35 | const query = { postId: postId } |
| 36 | if (omitReplies) { |
| 37 | query.replyToId = null |
| 38 | } |
| 39 | const result = await db.collection('comments').find(query) |
| 40 | return (await result.toArray()).map(({ _id: id, ...found }) => ({ |
| 41 | id, |
| 42 | ...found |
| 43 | })) |
| 44 | } |
| 45 | async function findReplies ({ commentId, publishedOnly = true }) { |
| 46 | const db = await makeDb() |
| 47 | const query = publishedOnly |