Commit 64ac1a89 authored by Piyaphorn Arphornsri's avatar Piyaphorn Arphornsri

add

parent b5bfc970
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.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);
}
};
const auth = require('./auth'); const auth = require('./auth');
const list = require('./list'); const list = require('./list');
const shop = require('./shop') const shop = require('./shop')
const promotion =require('./promotion');
module.exports = { module.exports = {
auth, auth,
list, list,
shop, shop,
promotion,
} }
\ No newline at end of file
const express = require("express");
const router = express.Router();
const promotiomController = require("../../controllers/promotion");
router.post("/add",promotiomController.addpromotion);
router.get('/all',promotiomController.getPromotion);
router.delete('/delete/:promotionId',promotiomController.deletePromotion);
router.get('/getListId/:id',promotiomController.getPromotionId);
router.put('/updateList/id',promotiomController.updatePromotion);
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment