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 sessionHandler from '../../../handlers/session' const { error, success } = replies export default { config: { pre: [sessionHandler, authorizeHandler], validate: { headers } }, handler: async (req, reply) => { try { const version = req.pre.authorization.session.version if (version !== 2) { return error(merge(makeError('CLICK-400', 'bad-version'), { reply })) } const userId = req.pre.session.user_id const merchantId = req.pre.authorization.merchant.id const order = await OrderAPI.show({ merchantId, userId }) success({ order, user: order.user }, reply) } catch (err) { log({ errCreateOrder: err }) error(merge(makeError(err), { reply })) } }, method: 'GET', path: '/v2/orders' }