diff --git a/controllers/OffersController.js b/controllers/OffersController.js index b6e1fc4..c88c621 100644 --- a/controllers/OffersController.js +++ b/controllers/OffersController.js @@ -4,8 +4,9 @@ import cloudinary from "cloudinary"; export const createOffer = async (req, res) => { try { + // console.log(req.body) const files = req.files.image; - + // console.log(req.body) // console.log(files) const myCloud = await cloudinary.uploader.upload(files.tempFilePath, { folder: "cmp/image", @@ -24,6 +25,7 @@ export const createOffer = async (req, res) => { bisunessName }); + // console.log(data) res.status(201).json({ success: true, msg: " create Offer Successfully!!", diff --git a/controllers/bannerController.js b/controllers/bannerController.js index a4594a8..e850c67 100644 --- a/controllers/bannerController.js +++ b/controllers/bannerController.js @@ -13,10 +13,11 @@ export const createBanner = async (req, res) => { folder: "cmp/image", }, function (error, result) { (result, error) }); - const { title, section, startDate, endDate } = req.body; + const { title, section, startDate, endDate, subTitle } = req.body; const data = await Banners.create({ title, + subTitle, image: { public_id: myCloud.public_id, url: myCloud.secure_url, @@ -84,6 +85,8 @@ export const updateBanner = async (req, res) => { try { const newBannerData = { title: req.body.title, + subTitle: req.body.subTitle, + section: req.body.section, startDate: req.body.startDate, endDate: req.body.endDate, diff --git a/middlewares/auth.js b/middlewares/auth.js index b268b2a..1b41d0f 100644 --- a/middlewares/auth.js +++ b/middlewares/auth.js @@ -4,27 +4,40 @@ import ErrorHander from "../Utils/errorhander.js" export const isAuthenticatedUser = async (req, res, next) => { try { - const { token } = req.cookies; - //const getToken = req.headers; + // const { token } = req.cookies; + const getToken = req.headers; + // // console.log(getToken.authorization) - // console.log(token) + // console.log(getToken) // //remove Bearer from token - // const token = getToken.authorization.slice(7); - // // console.log(token) + const fronttoken = getToken.authorization.slice(7); + //console.log(token) - if (!token) { + if (!fronttoken) { return res.status(400).json({ success: false, message: "Login to Access this resource", }); } + // if (!fronttoken) { + // return res.status(400).json({ + // success: false, + // message: "Login to Access this resource", + // }); + // } - const decoded = jwt.verify(token, process.env.JWT_SECRET); + //const decoded = jwt.verify(token, process.env.JWT_SECRET); + const frontdecoded = jwt.verify(fronttoken, process.env.JWT_SECRET); // console.log(decoded) - const user = await User.findById(decoded.id); + //const user = await User.findById(decoded.id); + const fuser = await User.findById(frontdecoded.id); + // if (fuser != null) { + // req.user = fuser; + // //console.log(fuser) + // } // console.log(user) - req.user = user; + req.user = fuser; // console.log(req.user) next(); diff --git a/models/bannerModel.js b/models/bannerModel.js index 1b4439e..04422d0 100644 --- a/models/bannerModel.js +++ b/models/bannerModel.js @@ -5,6 +5,10 @@ const bannerSchema = new mongoose.Schema( type: String, required: true }, + subTitle: { + type: String, + required: true + }, image: { public_id: { diff --git a/routes/OffersRoute.js b/routes/OffersRoute.js index bdc00f4..bd2d6e3 100644 --- a/routes/OffersRoute.js +++ b/routes/OffersRoute.js @@ -7,10 +7,11 @@ import { getOneOffer } from "../controllers/OffersController.js" const router = express.Router(); +import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js" -router.route("/offer/create/").post(createOffer) +router.route("/offer/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createOffer) router.route("/offer/getAll/").get(getAllOffer) router.route("/offer/getOne/:id").get(getOneOffer) -router.route("/offer/update/:id").put(updateOffer); -router.route("/offer/delete/:id").delete(deleteOffer); +router.route("/offer/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateOffer); +router.route("/offer/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOffer); export default router; \ No newline at end of file diff --git a/tmp/tmp-1-1655787766073 b/tmp/tmp-1-1655787766073 new file mode 100644 index 0000000..b9a863b Binary files /dev/null and b/tmp/tmp-1-1655787766073 differ diff --git a/tmp/tmp-1-1655793757214 b/tmp/tmp-1-1655793757214 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1655793757214 differ diff --git a/tmp/tmp-1-1655793848440 b/tmp/tmp-1-1655793848440 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1655793848440 differ diff --git a/tmp/tmp-1-1655794786361 b/tmp/tmp-1-1655794786361 new file mode 100644 index 0000000..a6426fd Binary files /dev/null and b/tmp/tmp-1-1655794786361 differ diff --git a/tmp/tmp-1-1655795259131 b/tmp/tmp-1-1655795259131 new file mode 100644 index 0000000..b9a863b Binary files /dev/null and b/tmp/tmp-1-1655795259131 differ diff --git a/tmp/tmp-1-1655826962511 b/tmp/tmp-1-1655826962511 new file mode 100644 index 0000000..25c7510 Binary files /dev/null and b/tmp/tmp-1-1655826962511 differ diff --git a/tmp/tmp-2-1655794867002 b/tmp/tmp-2-1655794867002 new file mode 100644 index 0000000..b9a863b Binary files /dev/null and b/tmp/tmp-2-1655794867002 differ diff --git a/tmp/tmp-2-1655795481957 b/tmp/tmp-2-1655795481957 new file mode 100644 index 0000000..25c7510 Binary files /dev/null and b/tmp/tmp-2-1655795481957 differ diff --git a/tmp/tmp-2-1655826995622 b/tmp/tmp-2-1655826995622 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655826995622 differ diff --git a/tmp/tmp-3-1655795787029 b/tmp/tmp-3-1655795787029 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-3-1655795787029 differ diff --git a/tmp/tmp-3-1655827126460 b/tmp/tmp-3-1655827126460 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655827126460 differ diff --git a/tmp/tmp-4-1655796153961 b/tmp/tmp-4-1655796153961 new file mode 100644 index 0000000..f61ad05 Binary files /dev/null and b/tmp/tmp-4-1655796153961 differ diff --git a/tmp/tmp-4-1655827217124 b/tmp/tmp-4-1655827217124 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-4-1655827217124 differ