index.js 1.69 KB
const Promotion = require("../../models/promotion");

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

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

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

exports.getPromotionId = async (req, res) => {
  try {
    const promotionId = req.params.id;
    let promotion = await Promotion.findOne({
      where: {
        id: promotionId
      }
    });
    res.status(200).send("success");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};
exports.getUserId = async (req, res) => {
  try {
    const userId = req.params.id;
    let promotion = await Promotion.findOne({
      where: {
        id: userId
      }
    });
    res.status(200).send("success");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};
exports.updatePromotion = async (req, res) => {
  try {
    const promotionData = req.body;
    const id = req.params.id;
    await promotion.update(promotionData, { where: { id: id } });
    res.status(200).send({ status: "done" });
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};