const Beautician = require("../../models/beautician");
const config = require("../../config");

exports.add = async (req, res) => {
  try {
    const addbeauticianData = req.body;
    console.log(addbeauticianData);
    await Beautician.create({
      name: addbeauticianData.name,
      email: addbeauticianData.email,
      address: addbeauticianData.address,
      tel: addbeauticianData.tel,
      shopID: addbeauticianData.shopID
    });
    res.send("create");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};

exports.getbeauticianShopId  = async (req, res) => {
  try {
    const id  = req.params.shopID;
    let beautician = await Beautician.findAll({
      where: {
        shopID: id
      }
    });
    console.log('beautician', beautician)
    res.status(200).send(beautician);
  } catch (err) {
    res.send({
      error: err.message
    });
  }
};
exports.getbeauticianName = async (req, res) => {
  try {
    const name  = req.params.name;
    let beautician = await Beautician.findAll({
      where: {
        name:name
      }
    });
    console.log('beautician', beautician)
    res.status(200).send(beautician);
  } catch (err) {
    res.send({
      error: err.message
    });
  }
};

exports.deletebeautician = async (req, res) => {
  try {
    const beauticianId = req.params.id;
    await Beautician.destroy({
      where: {
        id: beauticianId,
      },
    });
    res.status(200).send("success");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};