change all images fuctionality

This commit is contained in:
pawan-dot 2024-06-12 18:05:38 +05:30
parent e9b473a197
commit 56438a92aa
8 changed files with 336 additions and 159 deletions

5
.env
View File

@ -1,8 +1,8 @@
# DB_URL="mongodb+srv://smellica:Anjefef23dnsfjne@cluster0.c5gfqzm.mongodb.net/"
DB_URL="mongodb+srv://pulseayur:rEF9gYORzKavLeiy@cluster0.vi4tl1l.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
# pulseayur Data Connection
DB_URL="mongodb+srv://pulseayur:rEF9gYORzKavLeiy@cluster0.vi4tl1l.mongodb.net/"
# DB_URL="mongodb+srv://pulseayur:rEF9gYORzKavLeiy@cluster0.vi4tl1l.mongodb.net/"
# DB_URL="mongodb://localhost:27017/smellica"
PORT = 5000
@ -38,3 +38,4 @@ PAYPAL_CLIENT_ID="AemCjVuWswklp1sWUo4peCFg9eS4bofMsMR0RCrVRB2DifYR1IUSrWqtHpVmQl
PAYPAL_CLIENT_SECRET="EAo0Y9ff3jpHHg1QAbftdebfh7cb_-vnebhQrP9KALbCVer908yx2tO2eHO39r7EJSfqc4D69Qgx8R31"
STRIPE_SECRET="sk_test_51OhPRdSG6gbAOwcEid1GavJ4FTD0ZuHVTferdvJwKal77RlMtFJGBzL5GjtL0ie8ZJztsGjUWi8DWrnw1pDdDRGS005Hk0ahql"

View File

@ -2,7 +2,7 @@ import { PrivacyAndPolicy } from "./PrivacyPolicyModel.js";
import { Refundpolicy } from "./RefundModel.js";
import { Shipping } from "./ShippingModel.js";
import { TermsAndCondition } from "./TermsandConditonModel.js";
import { AboutUs } from './AboutUsModel.js'
import { AboutUs } from "./AboutUsModel.js";
export const AddTermsAndConditions = async (req, res) => {
try {
@ -54,15 +54,14 @@ export const updateTermsAndConditions = async (req, res) => {
if (!req?.user) return res.status(400).json({ message: "please login !" });
// new content
const { content } = req.body;
// id of the terms and conndition document
const id = req.query.id;
// object for updated terms and conndition data
const updatedTermsData = {
termsAndContionContent: content,
addedBy: req.user._id
}
addedBy: req.user._id,
};
// update the terms and conndition in database
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
@ -138,8 +137,8 @@ export const updateRefundPolicy = async (req, res) => {
// object for updated refund policy data
const updatedRefundPolicyData = {
Refundpolicy: content,
addedBy: req.user._id
}
addedBy: req.user._id,
};
// update the refund policy in database
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
@ -161,7 +160,6 @@ export const updateRefundPolicy = async (req, res) => {
}
};
// Privacy policy controller functions
export const AddPrivacyAndPolicy = async (req, res) => {
@ -222,8 +220,8 @@ export const updatePrivacyPolicy = async (req, res) => {
// object for updated privacy policy data
const updatedPrivacyPolicyData = {
privacyAndPolicyContent: content,
addedBy: req.user._id
}
addedBy: req.user._id,
};
// update the privacy policy in database
const privacyAndPolicy = await PrivacyAndPolicy.findByIdAndUpdate(
@ -304,8 +302,8 @@ export const updateShipping = async (req, res) => {
// object for updated shipping policy data
const updatedShippingData = {
shippingContent: content,
addedBy: req.user._id
}
addedBy: req.user._id,
};
// update the shipping policy in database
const shipping = await Shipping.findByIdAndUpdate(
@ -387,8 +385,8 @@ export const updateAboutUs = async (req, res) => {
// object for updated about us data
const updatedAboutUsData = {
aboutUsContent: content,
addedBy: req.user._id
}
addedBy: req.user._id,
};
// update the about us in database
const aboutUs = await AboutUs.findByIdAndUpdate(
@ -409,5 +407,3 @@ export const updateAboutUs = async (req, res) => {
});
}
};

View File

@ -18,7 +18,7 @@ export const addImage = async (req, res) => {
const result = await cloudinary.v2.uploader.upload(
bannerImage.tempFilePath,
{
folder: "GetSygnal/loginImage",
folder: "Ayurpulse/loginImage",
}
);
@ -84,7 +84,7 @@ export const getImage = async (req, res) => {
// const result = await cloudinary.v2.uploader.upload(
// bannerImag.tempFilePath,
// {
// folder: "GetSygnal/loginImage",
// folder: "Ayurpulse/loginImage",
// }
// );
@ -127,36 +127,27 @@ export const updateImage = async (req, res) => {
try {
if (!req?.user) return res.status(400).json({ message: "please login !" });
const { _id } = req.params;
const { bannerName } = req.body;
const olderImage = req.body?.olderImage;
const bannerImag = req.files?.bannerImage;
// console.log("bannerImag", bannerImag);
if (!mongoose.Types.ObjectId.isValid(_id)) {
return res.status(404).json({ error: "Can not find the document " });
}
// console.log(JSON.parse(olderImage).length);
// find the document with the id to delete the image from cloudinary
if (olderImage) {
const deletefromCloudinary = await LoginImageModel.findOne({ _id: _id });
// console.log("deletefromCloudinary", deletefromCloudinary)
const deleteresponse = await cloudinary.v2.uploader.destroy(
deletefromCloudinary.image.public_id
);
if (deleteresponse) {
const result = await cloudinary.v2.uploader.upload(
bannerImag.tempFilePath,
{
folder: "GetSygnal/loginImage",
folder: "Ayurpulse/loginImage",
}
);
console.log("result", result);
const update = await LoginImageModel.findOneAndUpdate(
{ _id: _id },
{ image: result }, // Provide the updated categoryName
@ -219,3 +210,58 @@ export const deleteImage = async (req, res) => {
});
}
};
export const CreateAndUpdateImage = async (req, res) => {
try {
const LoginImag = req.files?.LoginImg;
const findImage = await LoginImageModel.find();
if (findImage?.length > 0) {
const deleteImg = await cloudinary.v2.uploader.destroy(
findImage[0]?.image.public_id
);
if (deleteImg) {
const result = await cloudinary.v2.uploader.upload(
LoginImag.tempFilePath,
{
folder: "Ayurpulse/loginImage",
}
);
// console.log("result", result);
const update = await LoginImageModel.findOneAndUpdate(
{ _id: findImage[0]?._id },
{ image: result }, // Provide the updated categoryName
{ new: true } // To return the updated document
);
if (update)
return res
.status(200)
.json({ message: "Login Image Update successfully" });
}
} else {
const result = await cloudinary.v2.uploader.upload(
LoginImag.tempFilePath,
{
folder: "Ayurpulse/loginImage",
}
);
if (result) {
const regsiterImage = await LoginImageModel.create({
image: result,
addedBy: req.user._id,
});
if (regsiterImage) {
return res.status(201).json({
success: true,
regsiterImage,
message: " Login Image Added successfully",
});
}
}
}
} catch (error) {
res.status(500).json({
success: false,
message: error.message ? error.message : "Something went wrong",
});
}
};

View File

@ -3,6 +3,7 @@ import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
// import { addImage, deleteImage, getImage, updateImage } from "./RegistrationImageController.js";
import {
CreateAndUpdateImage,
addImage,
deleteImage,
getImage,
@ -17,6 +18,13 @@ router.route("/getImage").get(getImage);
router
.route("/update/:_id")
.patch(isAuthenticatedUser, authorizeRoles("admin", "Employee"), updateImage);
router
.route("/addmodify")
.post(
isAuthenticatedUser,
authorizeRoles("admin", "Employee"),
CreateAndUpdateImage
);
router
.route("/delete/:_id")
.delete(

View File

@ -18,7 +18,7 @@ export const addImage = async (req, res) => {
const result = await cloudinary.v2.uploader.upload(
bannerImage.tempFilePath,
{
folder: "GetSygnal/registrationImage",
folder: "Register/registrationImage",
}
);
@ -84,7 +84,7 @@ export const getImage = async (req, res) => {
// const result = await cloudinary.v2.uploader.upload(
// bannerImag.tempFilePath,
// {
// folder: "GetSygnal/registrationImage",
// folder: "Register/registrationImage",
// }
// );
@ -152,10 +152,10 @@ export const updateImage = async (req, res) => {
const result = await cloudinary.v2.uploader.upload(
bannerImag.tempFilePath,
{
folder: "GetSygnal/registrationImage",
folder: "Register/registrationImage",
}
);
console.log("result", result);
// console.log("result", result);
const update = await RegistrationImageModel.findOneAndUpdate(
{ _id: _id },
{ image: result }, // Provide the updated categoryName
@ -222,3 +222,58 @@ export const deleteImage = async (req, res) => {
});
}
};
export const CreateAndUpdateImage = async (req, res) => {
try {
const RegisterImag = req.files?.RegisterImglogo;
const findImage = await RegistrationImageModel.find();
if (findImage?.length > 0) {
const deleteImg = await cloudinary.v2.uploader.destroy(
findImage[0]?.image.public_id
);
if (deleteImg) {
const result = await cloudinary.v2.uploader.upload(
RegisterImag.tempFilePath,
{
folder: "Ayurpulse/RegisterImage",
}
);
// console.log("result", result);
const update = await RegistrationImageModel.findOneAndUpdate(
{ _id: findImage[0]?._id },
{ image: result }, // Provide the updated categoryName
{ new: true } // To return the updated document
);
if (update)
return res
.status(200)
.json({ message: "Register Image Update successfully" });
}
} else {
const result = await cloudinary.v2.uploader.upload(
RegisterImag.tempFilePath,
{
folder: "Ayurpulse/RegisterImage",
}
);
if (result) {
const regsiterImage = await RegistrationImageModel.create({
image: result,
addedBy: req.user._id,
});
if (regsiterImage) {
return res.status(201).json({
success: true,
regsiterImage,
message: " Register Image Added successfully",
});
}
}
}
} catch (error) {
res.status(500).json({
success: false,
message: error.message ? error.message : "Something went wrong",
});
}
};

View File

@ -6,6 +6,7 @@ import {
deleteImage,
getImage,
updateImage,
CreateAndUpdateImage,
} from "./RegistrationImageController.js";
const router = express.Router();
@ -16,6 +17,13 @@ router.route("/getImage").get(getImage);
router
.route("/update/:_id")
.patch(isAuthenticatedUser, authorizeRoles("admin", "Employee"), updateImage);
router
.route("/addmodify")
.post(
isAuthenticatedUser,
authorizeRoles("admin", "Employee"),
CreateAndUpdateImage
);
router
.route("/delete/:_id")
.delete(

View File

@ -155,7 +155,7 @@ export const updateImage = async (req, res) => {
folder: "GetSygnal/shopImage",
}
);
console.log("result", result);
// console.log("result", result);
const update = await ShopPageImageModel.findOneAndUpdate(
{ _id: _id },
{ image: result }, // Provide the updated categoryName
@ -220,3 +220,58 @@ export const deleteImage = async (req, res) => {
});
}
};
export const CreateAndUpdateImage = async (req, res) => {
try {
const ShopImag = req.files?.ShopImg;
const findImage = await ShopPageImageModel.find();
if (findImage?.length > 0) {
const deleteImg = await cloudinary.v2.uploader.destroy(
findImage[0]?.image.public_id
);
if (deleteImg) {
const result = await cloudinary.v2.uploader.upload(
ShopImag.tempFilePath,
{
folder: "Ayurpulse/ShopImage",
}
);
// console.log("result", result);
const update = await ShopPageImageModel.findOneAndUpdate(
{ _id: findImage[0]?._id },
{ image: result }, // Provide the updated categoryName
{ new: true } // To return the updated document
);
if (update)
return res
.status(200)
.json({ message: "Shop Image Update successfully" });
}
} else {
const result = await cloudinary.v2.uploader.upload(
ShopImag.tempFilePath,
{
folder: "Ayurpulse/shopImage",
}
);
if (result) {
const shopImage = await ShopPageImageModel.create({
image: result,
addedBy: req.user._id,
});
if (shopImage) {
return res.status(201).json({
success: true,
shopImage,
message: " Shop Image Added successfully",
});
}
}
}
} catch (error) {
res.status(500).json({
success: false,
message: error.message ? error.message : "Something went wrong",
});
}
};

View File

@ -5,6 +5,7 @@ import {
deleteImage,
getImage,
updateImage,
CreateAndUpdateImage,
} from "./ShopPageImageController.js";
// import { addImage, deleteImage, getImage, updateImage } from "./RegistrationImageController.js";
@ -18,6 +19,13 @@ router.route("/getImage").get(getImage);
router
.route("/update/:_id")
.patch(isAuthenticatedUser, authorizeRoles("admin", "Employee"), updateImage);
router
.route("/addmodify")
.post(
isAuthenticatedUser,
authorizeRoles("admin", "Employee"),
CreateAndUpdateImage
);
router
.route("/delete/:_id")
.delete(