text: const httpStatus = require('http-status');
  const pick = require('../utils/pick');
  const ApiError = require('../utils/ApiError');
  const catchAsync = require('../utils/catchAsync');
  const {
    orderService
  } = require('../services');
  
  const createOrder = catchAsync(async (req, res) => {
    const order = await orderService.createOrder(req.body);
    res.status(httpStatus.CREATED).send(order);
  });
  
  const getOrders = catchAsync(async (req, res) => {
    const filter = pick(req.query, ['name', 'role']);
    const options = pick(req.query, ['sortBy', 'limit', 'page']);
    const result = await orderService.queryOrders(filter, options);
    res.send(result);
  });
  
  const getOrder = catchAsync(async (req, res) => {
    const order = await orderService.getOrderByOrderId(req.params.orderId);
    if (!order || !order.length) {
      throw new ApiError(httpStatus.NOT_FOUND, 'Order error');
    }
    res.send({
      order,
      code: 1,
    });
  });
  
  const updateOrder = catchAsync(async (req, res) => {
    const order = await orderService.updateOrderById(req.params.orderId, req.body);
    if (!order) {
      throw new ApiError(httpStatus.NOT_FOUND, 'Order update error');
    }
    res.send({
      order,
      code: 1,
    });
  });
  
  const deleteOrder = catchAsync(async (req, res) => {
    await orderService.deleteOrderById(req.params.orderId);
    res.send({ code: 1, message: 'Xoá đơn hàng thành công' });
  });
  
  module.exports = {
    createOrder,
    getOrders,
    getOrder,
    updateOrder,
    deleteOrder,
  };
  