diff --git a/controllers/OffersController.js b/controllers/OffersController.js index c88c621..43f20b1 100644 --- a/controllers/OffersController.js +++ b/controllers/OffersController.js @@ -4,10 +4,8 @@ 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", }, @@ -25,7 +23,6 @@ export const createOffer = async (req, res) => { bisunessName }); - // console.log(data) res.status(201).json({ success: true, msg: " create Offer Successfully!!", @@ -44,7 +41,6 @@ export const getAllOffer = async (req, res) => { try { const offer = await Offers.find(); - // console.log(category) res.status(200).json({ success: true, msg: " fetch All Offer Successfully!!", @@ -63,14 +59,13 @@ export const getOneOffer = async (req, res) => { try { const offer = await Offers.findById(req.params.id); - // console.log(category) + res.status(200).json({ success: true, msg: " fetch Successfully!!", offer, }); } catch (error) { - // console.log(error) res.status(500).json({ success: false, msg: "Failled to fetch !!" @@ -95,15 +90,12 @@ export const updateOffer = async (req, res) => { const getOffer = await Offers.findById(req.params.id); const imageId = getOffer.image.public_id; - // console.log(imageId) - //delete image from claudinary + await cloudinary.uploader.destroy(imageId) - // await cloudinary.uploader.destroy(imageId, function (result) { console.log(result) }); const myCloud = await cloudinary.uploader.upload(files.tempFilePath, { folder: "image", }, function (error, result) { (result, error) }); - // console.log(myCloud) newOfferData.image = { public_id: myCloud.public_id, url: myCloud.secure_url, @@ -114,8 +106,7 @@ export const updateOffer = async (req, res) => { const ModifyOffer = await Offers.findByIdAndUpdate(req.params.id, newOfferData, { new: true } - // runValidators: true, - // useFindAndModify: false, + ); res.status(200).json({ diff --git a/controllers/bannerController.js b/controllers/bannerController.js index e850c67..6ff2759 100644 --- a/controllers/bannerController.js +++ b/controllers/bannerController.js @@ -8,13 +8,13 @@ export const createBanner = async (req, res) => { try { const files = req.files.image; + // console.log(files) const myCloud = await cloudinary.uploader.upload(files.tempFilePath, { folder: "cmp/image", }, function (error, result) { (result, error) }); const { title, section, startDate, endDate, subTitle } = req.body; - const data = await Banners.create({ title, subTitle, @@ -27,12 +27,14 @@ export const createBanner = async (req, res) => { endDate }); + res.status(201).json({ success: true, msg: " create Banner Successfully!!", data, }); } catch (error) { + // console.log(error) res.status(500).json({ success: false, msg: "Failled to create Banner !!" diff --git a/middlewares/auth.js b/middlewares/auth.js index 1b41d0f..5215e6a 100644 --- a/middlewares/auth.js +++ b/middlewares/auth.js @@ -5,8 +5,14 @@ import ErrorHander from "../Utils/errorhander.js" export const isAuthenticatedUser = async (req, res, next) => { try { // const { token } = req.cookies; - const getToken = req.headers; + const getToken = req.headers; + if (!getToken) { + return res.status(400).json({ + success: false, + message: "Login to Access this resource", + }); + } // // console.log(getToken.authorization) // console.log(getToken) @@ -17,7 +23,7 @@ export const isAuthenticatedUser = async (req, res, next) => { if (!fronttoken) { return res.status(400).json({ success: false, - message: "Login to Access this resource", + message: "Login to Access this resource token", }); } // if (!fronttoken) { diff --git a/routes/bannerRoute.js b/routes/bannerRoute.js index 8ab39d4..e2f14b3 100644 --- a/routes/bannerRoute.js +++ b/routes/bannerRoute.js @@ -7,7 +7,7 @@ import { getOneBanner } from "../controllers/bannerController.js" const router = express.Router(); - +import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js" router.route("/banner/create/").post(createBanner) router.route("/banner/getAll/").get(getAllBanner) router.route("/banner/getOne/:id").get(getOneBanner) diff --git a/tmp/tmp-1-1655970064628 b/tmp/tmp-1-1655970064628 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655970064628 differ diff --git a/tmp/tmp-1-1655970163588 b/tmp/tmp-1-1655970163588 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655970163588 differ diff --git a/tmp/tmp-1-1655970446002 b/tmp/tmp-1-1655970446002 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1655970446002 differ diff --git a/tmp/tmp-1-1655971046217 b/tmp/tmp-1-1655971046217 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1655971046217 differ diff --git a/tmp/tmp-1-1655971805691 b/tmp/tmp-1-1655971805691 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655971805691 differ diff --git a/tmp/tmp-1-1655972354067 b/tmp/tmp-1-1655972354067 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972354067 differ diff --git a/tmp/tmp-1-1655972492909 b/tmp/tmp-1-1655972492909 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972492909 differ diff --git a/tmp/tmp-1-1655972563013 b/tmp/tmp-1-1655972563013 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972563013 differ diff --git a/tmp/tmp-1-1655972581720 b/tmp/tmp-1-1655972581720 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972581720 differ diff --git a/tmp/tmp-1-1655972644905 b/tmp/tmp-1-1655972644905 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972644905 differ diff --git a/tmp/tmp-1-1655972775829 b/tmp/tmp-1-1655972775829 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972775829 differ diff --git a/tmp/tmp-1-1655972888130 b/tmp/tmp-1-1655972888130 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972888130 differ diff --git a/tmp/tmp-1-1655972990452 b/tmp/tmp-1-1655972990452 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655972990452 differ diff --git a/tmp/tmp-1-1655973060170 b/tmp/tmp-1-1655973060170 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1655973060170 differ diff --git a/tmp/tmp-10-1655972743712 b/tmp/tmp-10-1655972743712 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-10-1655972743712 differ diff --git a/tmp/tmp-11-1655972744922 b/tmp/tmp-11-1655972744922 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-11-1655972744922 differ diff --git a/tmp/tmp-12-1655972746446 b/tmp/tmp-12-1655972746446 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-12-1655972746446 differ diff --git a/tmp/tmp-13-1655972747702 b/tmp/tmp-13-1655972747702 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-13-1655972747702 differ diff --git a/tmp/tmp-14-1655972748819 b/tmp/tmp-14-1655972748819 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-14-1655972748819 differ diff --git a/tmp/tmp-15-1655972750007 b/tmp/tmp-15-1655972750007 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-15-1655972750007 differ diff --git a/tmp/tmp-16-1655972751424 b/tmp/tmp-16-1655972751424 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-16-1655972751424 differ diff --git a/tmp/tmp-17-1655972752626 b/tmp/tmp-17-1655972752626 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-17-1655972752626 differ diff --git a/tmp/tmp-2-1655970253011 b/tmp/tmp-2-1655970253011 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-2-1655970253011 differ diff --git a/tmp/tmp-2-1655970836223 b/tmp/tmp-2-1655970836223 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-2-1655970836223 differ diff --git a/tmp/tmp-2-1655971379121 b/tmp/tmp-2-1655971379121 new file mode 100644 index 0000000..f61ad05 Binary files /dev/null and b/tmp/tmp-2-1655971379121 differ diff --git a/tmp/tmp-2-1655972494837 b/tmp/tmp-2-1655972494837 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972494837 differ diff --git a/tmp/tmp-2-1655972565632 b/tmp/tmp-2-1655972565632 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972565632 differ diff --git a/tmp/tmp-2-1655972583625 b/tmp/tmp-2-1655972583625 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972583625 differ diff --git a/tmp/tmp-2-1655972646309 b/tmp/tmp-2-1655972646309 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972646309 differ diff --git a/tmp/tmp-2-1655972779981 b/tmp/tmp-2-1655972779981 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972779981 differ diff --git a/tmp/tmp-2-1655972890321 b/tmp/tmp-2-1655972890321 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972890321 differ diff --git a/tmp/tmp-2-1655972992160 b/tmp/tmp-2-1655972992160 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1655972992160 differ diff --git a/tmp/tmp-3-1655972496179 b/tmp/tmp-3-1655972496179 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655972496179 differ diff --git a/tmp/tmp-3-1655972566968 b/tmp/tmp-3-1655972566968 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655972566968 differ diff --git a/tmp/tmp-3-1655972585061 b/tmp/tmp-3-1655972585061 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655972585061 differ diff --git a/tmp/tmp-3-1655972647641 b/tmp/tmp-3-1655972647641 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655972647641 differ diff --git a/tmp/tmp-3-1655972819196 b/tmp/tmp-3-1655972819196 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655972819196 differ diff --git a/tmp/tmp-3-1655972931608 b/tmp/tmp-3-1655972931608 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-3-1655972931608 differ diff --git a/tmp/tmp-4-1655972497375 b/tmp/tmp-4-1655972497375 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-4-1655972497375 differ diff --git a/tmp/tmp-4-1655972586262 b/tmp/tmp-4-1655972586262 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-4-1655972586262 differ diff --git a/tmp/tmp-4-1655972648850 b/tmp/tmp-4-1655972648850 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-4-1655972648850 differ diff --git a/tmp/tmp-4-1655972933242 b/tmp/tmp-4-1655972933242 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-4-1655972933242 differ diff --git a/tmp/tmp-5-1655972505559 b/tmp/tmp-5-1655972505559 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-5-1655972505559 differ diff --git a/tmp/tmp-5-1655972587344 b/tmp/tmp-5-1655972587344 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-5-1655972587344 differ diff --git a/tmp/tmp-5-1655972649948 b/tmp/tmp-5-1655972649948 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-5-1655972649948 differ diff --git a/tmp/tmp-5-1655972934690 b/tmp/tmp-5-1655972934690 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-5-1655972934690 differ diff --git a/tmp/tmp-6-1655972588413 b/tmp/tmp-6-1655972588413 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-6-1655972588413 differ diff --git a/tmp/tmp-6-1655972651087 b/tmp/tmp-6-1655972651087 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-6-1655972651087 differ diff --git a/tmp/tmp-6-1655972936218 b/tmp/tmp-6-1655972936218 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-6-1655972936218 differ diff --git a/tmp/tmp-7-1655972652262 b/tmp/tmp-7-1655972652262 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-7-1655972652262 differ diff --git a/tmp/tmp-7-1655972937734 b/tmp/tmp-7-1655972937734 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-7-1655972937734 differ diff --git a/tmp/tmp-8-1655972653368 b/tmp/tmp-8-1655972653368 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-8-1655972653368 differ diff --git a/tmp/tmp-9-1655972741391 b/tmp/tmp-9-1655972741391 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-9-1655972741391 differ