const Review = require("../../models/reviews");

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

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

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

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

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