({ publishedOnly = true } = {})
| 12 | update |
| 13 | }) |
| 14 | async function findAll ({ publishedOnly = true } = {}) { |
| 15 | const db = await makeDb() |
| 16 | const query = publishedOnly ? { published: true } : {} |
| 17 | const result = await db.collection('comments').find(query) |
| 18 | return (await result.toArray()).map(({ _id: id, ...found }) => ({ |
| 19 | id, |
| 20 | ...found |
| 21 | })) |
| 22 | } |
| 23 | async function findById ({ id: _id }) { |
| 24 | const db = await makeDb() |
| 25 | const result = await db.collection('comments').find({ _id }) |