const router = require("express-promise-router")();

const storagebeautician = require("../../multer");
const BeauticianImage = require("../../models/beauticianImg");
const User = require("../../models/user");

router.post(
  "/upload/beautician/:beauticianId",storagebeautician.single("images"),async (req, res) => {
    //  console.log(req.body.shopId);
    const images = req.file;
    const shop_id = req.body.shopId;
    const beautician_id = req.params.beauticianId;
    // console.log(req);

    await BeauticianImage.create({
      beautician_id: req.params.beauticianId,
      image: images.buffer,
      type: images.mimetype,
    });
    res.send("success");
  }
);
//get file
router.get('/file/beautician/:beauticianId', async (req, res) => {
  const existingImage = await ShopImage.findAll({
      where: {
        beautician_id: req.params.beauticianId
      }
  })
  const urlimg = existingImage.image.toString('base64');
  const dataimg = {
      url: urlimg,
      type: existingImage.type
  }
  res.status(200).send(dataimg);
})
module.exports = router;
