const { uploadImage } = require("../utils/imgUpload");
const multer = require("multer");

exports.uploadSingleImg = async (req, res, next) => {
  try {
    const upload = uploadImage.single("img");
    upload(req, res, function (err) {
      if (err instanceof multer.MulterError) {
        return res.status(400).json({ success: false, msg: err.message });
      } else if (err) {
        return res.status(500).json({ success: false, msg: err });
      }
      next();
    });
  } catch (err) {
    return res
      .status(500)
      .json({ success: false, msg: "Something went wrong!" });
  }
};
