({ editComment })
| 1 | export default function makePatchComment ({ editComment }) { |
| 2 | return async function patchComment (httpRequest) { |
| 3 | try { |
| 4 | const { source = {}, ...commentInfo } = httpRequest.body |
| 5 | source.ip = httpRequest.ip |
| 6 | source.browser = httpRequest.headers['User-Agent'] |
| 7 | if (httpRequest.headers['Referer']) { |
| 8 | source.referrer = httpRequest.headers['Referer'] |
| 9 | } |
| 10 | const toEdit = { |
| 11 | ...commentInfo, |
| 12 | source, |
| 13 | id: httpRequest.params.id |
| 14 | } |
| 15 | const patched = await editComment(toEdit) |
| 16 | return { |
| 17 | headers: { |
| 18 | 'Content-Type': 'application/json', |
| 19 | 'Last-Modified': new Date(patched.modifiedOn).toUTCString() |
| 20 | }, |
| 21 | statusCode: 200, |
| 22 | body: { patched } |
| 23 | } |
| 24 | } catch (e) { |
| 25 | // TODO: Error logging |
| 26 | console.log(e) |
| 27 | if (e.name === 'RangeError') { |
| 28 | return { |
| 29 | headers: { |
| 30 | 'Content-Type': 'application/json' |
| 31 | }, |
| 32 | statusCode: 404, |
| 33 | body: { |
| 34 | error: e.message |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | return { |
| 39 | headers: { |
| 40 | 'Content-Type': 'application/json' |
| 41 | }, |
| 42 | statusCode: 400, |
| 43 | body: { |
| 44 | error: e.message |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
no outgoing calls
no test coverage detected