const Shop = require("../../models/shop");

exports.addShop = async (req, res) => {
  try {
    const addshopData = req.body;
    console.log(addshopData);
    await Shop.create(addshopData);
    res.send("create");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};

exports.getShop = async (req, res) => {
  try {
    let shop = await Shop.findAll();
    res.status(200).send("success");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};

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

exports.getShopId = async (req, res) => {
  try {
    const shopId = req.params.id;
    let shop = await Shop.findOne({
      where: {
        id: shopId
      }
    });
    res.status(200).send("success");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};

exports.updateShop = async (req, res) => {
  try {
    const shopData = req.body;
    const id = req.params.id;
    await Shop.update(shopData, { where: { id: id } });
    res.status(200).send({ status: "done" });
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};
