2021-05-03 03:44:33 -07:00
|
|
|
const express = require("express");
|
2021-05-05 06:34:23 -07:00
|
|
|
const couponController = require('../controllers/coupon') ;
|
|
|
|
|
|
|
|
const isAuth = require('../middleware/requirelogin') ;
|
|
|
|
const isAdmin = require('../middleware/isAdmin') ;
|
2021-05-03 03:21:15 -07:00
|
|
|
|
2021-05-03 03:44:33 -07:00
|
|
|
const router = express.Router();
|
2021-05-03 03:21:15 -07:00
|
|
|
|
|
|
|
|
2021-05-03 03:44:33 -07:00
|
|
|
router.post("/set-coupon", (req, res) => {
|
2021-05-03 07:38:30 -07:00
|
|
|
const { percentage, coupon_code ,remainingTimes} = req.body;
|
|
|
|
if(!coupon_code || !percentage || !remainingTimes){
|
|
|
|
return res.status(422).json({error:"Add all fields"})
|
|
|
|
}else{
|
|
|
|
const coupon = new Coupon({
|
2021-05-03 03:44:33 -07:00
|
|
|
coupon_code,
|
|
|
|
percentage,
|
2021-05-03 07:38:30 -07:00
|
|
|
remainingTimes
|
2021-05-03 03:44:33 -07:00
|
|
|
});
|
|
|
|
coupon.save().then((result) => {
|
|
|
|
res.status(200).json({ message: "Coupon set Successfully" });
|
|
|
|
});
|
2021-05-03 07:38:30 -07:00
|
|
|
}
|
2021-05-03 03:44:33 -07:00
|
|
|
});
|
2021-05-10 03:10:10 -07:00
|
|
|
=======
|
2021-05-05 06:34:23 -07:00
|
|
|
router.get("/getAllCoupons",isAuth , isAdmin , couponController.getAllCoupons);
|
2021-05-03 03:21:15 -07:00
|
|
|
|
2021-05-03 03:44:33 -07:00
|
|
|
|
2021-05-05 06:34:23 -07:00
|
|
|
router.post("/addCoupon", isAuth , isAdmin ,couponController.addCoupon);
|
2021-05-03 03:44:33 -07:00
|
|
|
|
2021-05-05 06:34:23 -07:00
|
|
|
router.post("/deleteCoupon", isAuth , isAdmin ,couponController.deleteCoupon);
|
2021-05-03 03:21:15 -07:00
|
|
|
|
2021-05-03 03:44:33 -07:00
|
|
|
module.exports = router;
|