import { makeError, replies } from '@oyst/utils' import OrderAPI from '../../../apis/order' import authorizeHandler from '../../../handlers/authorize' import { fullSession as headers } from '../../../validators/headers' import log from '../../../lib/log' import { merge } from 'ramda' import { updateItem as payload } from '../../../validators/orders' import sessionHandler from '../../../handlers/session' const { error } = replies export default { config: { pre: [sessionHandler, authorizeHandler], validate: { headers, payload } }, handler: async (req, reply) => { const { orderId, itemId } = req.params try { reply(await OrderAPI.updateItem(orderId, itemId, req.payload)) } catch (errUpdateItem) { console.log({ errUpdateItem }) error(merge(makeError(errUpdateItem), { reply })) } }, method: 'PATCH', path: '/v2/orders/{orderId}/items/{itemId}' }