({ removeComment })
| 1 | export default function makeDeleteComment ({ removeComment }) { |
| 2 | return async function deleteComment (httpRequest) { |
| 3 | const headers = { |
| 4 | 'Content-Type': 'application/json' |
| 5 | } |
| 6 | try { |
| 7 | const deleted = await removeComment({ id: httpRequest.params.id }) |
| 8 | return { |
| 9 | headers, |
| 10 | statusCode: deleted.deletedCount === 0 ? 404 : 200, |
| 11 | body: { deleted } |
| 12 | } |
| 13 | } catch (e) { |
| 14 | // TODO: Error logging |
| 15 | console.log(e) |
| 16 | return { |
| 17 | headers, |
| 18 | statusCode: 400, |
| 19 | body: { |
| 20 | error: e.message |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | } |