From b61436183befb3d232e5a77090a3ac8e89529413 Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:43:31 +0530 Subject: [PATCH] add category banner image --- .gitignore | 3 ++- controllers/categoryController.js | 6 +++--- models/categoryModel.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9b31034..c303fe9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -.env \ No newline at end of file +.env +tmp \ No newline at end of file diff --git a/controllers/categoryController.js b/controllers/categoryController.js index c0c57e7..4e64d7c 100644 --- a/controllers/categoryController.js +++ b/controllers/categoryController.js @@ -114,14 +114,13 @@ export const updateCategory = async (req, res) => { }; } if (req.files.category_banner) { - if (categ.category_banner) { + if (categ.category_banner.public_id) { const imageId = categ.category_banner.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 files = req.files.category_banner; const BannerImage = await cloudinary.uploader.upload(files.tempFilePath, { folder: "image", @@ -138,6 +137,7 @@ export const updateCategory = async (req, res) => { } // console.log(newCategoryData) + //req.user.id, const ModifyCategory = await Category.findByIdAndUpdate(req.params.id, newCategoryData, diff --git a/models/categoryModel.js b/models/categoryModel.js index 556dd88..5f95360 100644 --- a/models/categoryModel.js +++ b/models/categoryModel.js @@ -20,11 +20,11 @@ const categorySchema = new mongoose.Schema( { public_id: { type: String, - required: true, + // required: true, }, url: { type: String, - required: true, + // required: true, }, }, addedOn: {