added home page panels
This commit is contained in:
parent
5431ee3392
commit
6fa092e82e
6
app.js
6
app.js
@ -163,6 +163,8 @@ import SeoRoute from "./resources/SEO&Analytics/SEORouter.js";
|
|||||||
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
||||||
//Blog Routes
|
//Blog Routes
|
||||||
import BlogRoute from "./resources/Blog/BlogRoute.js";
|
import BlogRoute from "./resources/Blog/BlogRoute.js";
|
||||||
|
// Panel Routes
|
||||||
|
import PanelRoute from "./resources/Panels/PanelRoutes.js"
|
||||||
//Coupon Routes
|
//Coupon Routes
|
||||||
import CouponRoute from "./resources/Affiliate&Coupon/Coupon/CouponRoute.js";
|
import CouponRoute from "./resources/Affiliate&Coupon/Coupon/CouponRoute.js";
|
||||||
//short urls
|
//short urls
|
||||||
@ -222,6 +224,10 @@ app.use("/api/v1/affiliate", AffiliateRoute);
|
|||||||
app.use("/api/v1/coupon", CouponRoute);
|
app.use("/api/v1/coupon", CouponRoute);
|
||||||
//Blog
|
//Blog
|
||||||
app.use("/api/v1/blog", BlogRoute);
|
app.use("/api/v1/blog", BlogRoute);
|
||||||
|
// panels
|
||||||
|
app.use("/api/panel", PanelRoute);
|
||||||
|
|
||||||
|
|
||||||
//config specialty
|
//config specialty
|
||||||
// app.use("/api/config/specialty", SpecialtiesRouter);
|
// app.use("/api/config/specialty", SpecialtiesRouter);
|
||||||
//specialties
|
//specialties
|
||||||
|
38
resources/Panels/Panel1Model.js
Normal file
38
resources/Panels/Panel1Model.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const panel1Schema = new Schema(
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
public_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addedBy: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
displayPanel: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Panel1 = model(
|
||||||
|
"Panel1",
|
||||||
|
panel1Schema
|
||||||
|
);
|
38
resources/Panels/Panel2Model.js
Normal file
38
resources/Panels/Panel2Model.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const panel2Schema = new Schema(
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
public_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addedBy: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
displayPanel: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Panel2 = model(
|
||||||
|
"Panel2",
|
||||||
|
panel2Schema
|
||||||
|
);
|
38
resources/Panels/Panel3Model.js
Normal file
38
resources/Panels/Panel3Model.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const panel3Schema = new Schema(
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
public_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addedBy: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
displayPanel: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Panel3 = model(
|
||||||
|
"Panel3",
|
||||||
|
panel3Schema
|
||||||
|
);
|
38
resources/Panels/Panel4Model.js
Normal file
38
resources/Panels/Panel4Model.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const panel4Schema = new Schema(
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
public_id: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
addedBy: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
displayPanel: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Panel4 = model(
|
||||||
|
"Panel4",
|
||||||
|
panel4Schema
|
||||||
|
);
|
547
resources/Panels/PanelController.js
Normal file
547
resources/Panels/PanelController.js
Normal file
@ -0,0 +1,547 @@
|
|||||||
|
import cloudinary from "../../Utils/cloudinary.js";
|
||||||
|
import { Panel1 } from "./Panel1Model.js";
|
||||||
|
import { Panel2 } from "./Panel2Model.js";
|
||||||
|
import { Panel3 } from "./Panel3Model.js";
|
||||||
|
import { Panel4 } from "./Panel4Model.js";
|
||||||
|
|
||||||
|
|
||||||
|
export const AddPanel1 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
req.body.user = req.user._id;
|
||||||
|
const { content,title,displayPanel} = req.body;
|
||||||
|
let image; // To store Cloudinary image details
|
||||||
|
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
const imageFile = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
imageFile.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the blog post
|
||||||
|
const panel1 = await Panel1.create({
|
||||||
|
title,
|
||||||
|
image,
|
||||||
|
content,
|
||||||
|
displayPanel,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
panel1,
|
||||||
|
message: "Added successfully",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getPanel1 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
const panel1 = await Panel1.find();
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
panel1,
|
||||||
|
message: "Found successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updatePanel1 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
|
// Check if the user is authenticated
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "Please login!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructure request body
|
||||||
|
const { title, content,displayPanel } = req.body;
|
||||||
|
|
||||||
|
// Prepare an object for the updated testimonial data
|
||||||
|
const updatedPanel1Data = {
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
displayPanel
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if files are uploaded
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
// If image file is uploaded, upload it to cloudinary
|
||||||
|
const uploadedImage = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
uploadedImage.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Prepare the image object with public_id and url
|
||||||
|
const image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Assign the uploaded image to the Blog's image field
|
||||||
|
updatedPanel1Data.image = image;
|
||||||
|
}
|
||||||
|
const modifiedPanel = await Panel1.findOneAndUpdate(
|
||||||
|
{ _id: req.params.id },
|
||||||
|
{ $set: updatedPanel1Data },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
ModifyBlog: modifiedPanel,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const AddPanel2 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
req.body.user = req.user._id;
|
||||||
|
const { content,title,displayPanel} = req.body;
|
||||||
|
let image; // To store Cloudinary image details
|
||||||
|
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
const imageFile = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
imageFile.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the blog post
|
||||||
|
const panel2 = await Panel2.create({
|
||||||
|
title,
|
||||||
|
image,
|
||||||
|
content,
|
||||||
|
displayPanel,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
panel2,
|
||||||
|
message: "Added successfully",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getPanel2 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
const panel2 = await Panel2.find();
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
panel2,
|
||||||
|
message: "Found successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updatePanel2 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
|
// Check if the user is authenticated
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "Please login!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructure request body
|
||||||
|
const { title, content,displayPanel } = req.body;
|
||||||
|
|
||||||
|
// Prepare an object for the updated testimonial data
|
||||||
|
const updatedPanel2Data = {
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
displayPanel
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if files are uploaded
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
// If image file is uploaded, upload it to cloudinary
|
||||||
|
const uploadedImage = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
uploadedImage.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Prepare the image object with public_id and url
|
||||||
|
const image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Assign the uploaded image to the Blog's image field
|
||||||
|
updatedPanel2Data.image = image;
|
||||||
|
}
|
||||||
|
const modifiedPanel = await Panel2.findOneAndUpdate(
|
||||||
|
{ _id: req.params.id },
|
||||||
|
{ $set: updatedPanel2Data },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
ModifyBlog: modifiedPanel,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const AddPanel3 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
req.body.user = req.user._id;
|
||||||
|
const { content,title,displayPanel} = req.body;
|
||||||
|
let image; // To store Cloudinary image details
|
||||||
|
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
const imageFile = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
imageFile.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the blog post
|
||||||
|
const panel3 = await Panel3.create({
|
||||||
|
title,
|
||||||
|
image,
|
||||||
|
content,
|
||||||
|
displayPanel,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
panel3,
|
||||||
|
message: "Added successfully",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getPanel3 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
const panel3 = await Panel3.find();
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
panel3,
|
||||||
|
message: "Found successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updatePanel3 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
|
// Check if the user is authenticated
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "Please login!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructure request body
|
||||||
|
const { title, content,displayPanel } = req.body;
|
||||||
|
|
||||||
|
// Prepare an object for the updated testimonial data
|
||||||
|
const updatedPanel3Data = {
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
displayPanel
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if files are uploaded
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
// If image file is uploaded, upload it to cloudinary
|
||||||
|
const uploadedImage = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
uploadedImage.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Prepare the image object with public_id and url
|
||||||
|
const image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Assign the uploaded image to the Blog's image field
|
||||||
|
updatedPanel3Data.image = image;
|
||||||
|
}
|
||||||
|
const modifiedPanel = await Panel3.findOneAndUpdate(
|
||||||
|
{ _id: req.params.id },
|
||||||
|
{ $set: updatedPanel3Data },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
ModifyBlog: modifiedPanel,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AddPanel4 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
req.body.user = req.user._id;
|
||||||
|
const { content,title,displayPanel} = req.body;
|
||||||
|
let image; // To store Cloudinary image details
|
||||||
|
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
const imageFile = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
imageFile.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the blog post
|
||||||
|
const panel4 = await Panel4.create({
|
||||||
|
title,
|
||||||
|
image,
|
||||||
|
content,
|
||||||
|
displayPanel,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
panel4,
|
||||||
|
message: "Added successfully",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getPanel4 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
const panel4 = await Panel4.find();
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
panel4,
|
||||||
|
message: "Found successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updatePanel4 = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
|
// Check if the user is authenticated
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "Please login!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructure request body
|
||||||
|
const { title, content,displayPanel } = req.body;
|
||||||
|
|
||||||
|
// Prepare an object for the updated testimonial data
|
||||||
|
const updatePanel4Data = {
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
displayPanel
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if files are uploaded
|
||||||
|
if (req.files && req.files.image) {
|
||||||
|
// If image file is uploaded, upload it to cloudinary
|
||||||
|
const uploadedImage = req.files.image;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
uploadedImage.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "smellica/blog",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Prepare the image object with public_id and url
|
||||||
|
const image = {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Assign the uploaded image to the Blog's image field
|
||||||
|
updatePanel4Data.image = image;
|
||||||
|
}
|
||||||
|
const modifiedPanel = await Panel4.findOneAndUpdate(
|
||||||
|
{ _id: req.params.id },
|
||||||
|
{ $set: updatePanel4Data },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
ModifyBlog: modifiedPanel,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteImageFromCloudinary = async (req, res) => {
|
||||||
|
const { public_id } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!public_id) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
msg: "Please Provide Product ID!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const response = await cloudinary.v2.uploader.destroy(public_id);
|
||||||
|
if (response) {
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: "Deleted Successfully!!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
msg: error.message ? error.message : "Something went wrong!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
59
resources/Panels/PanelRoutes.js
Normal file
59
resources/Panels/PanelRoutes.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import express from "express";
|
||||||
|
|
||||||
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
|
import { AddPanel1, AddPanel2, AddPanel3, AddPanel4, deleteImageFromCloudinary, getPanel1, getPanel2, getPanel3, getPanel4, updatePanel1, updatePanel2, updatePanel3, updatePanel4 } from "./PanelController.js";
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel1/add")
|
||||||
|
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel1);
|
||||||
|
router
|
||||||
|
.route("/panel1/get")
|
||||||
|
.get(getPanel1);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel1/update/:id")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel1);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel2/add")
|
||||||
|
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel2);
|
||||||
|
router
|
||||||
|
.route("/panel2/get")
|
||||||
|
.get(getPanel2);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel2/update/:id")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel2);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel3/add")
|
||||||
|
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel3);
|
||||||
|
router
|
||||||
|
.route("/panel3/get")
|
||||||
|
.get(getPanel3);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel3/update/:id")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel3);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel4/add")
|
||||||
|
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel4);
|
||||||
|
router
|
||||||
|
.route("/panel4/get")
|
||||||
|
.get(getPanel4);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/panel4/update/:id")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel4);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/deleteImage/jatinMor/panel/:public_id")
|
||||||
|
.delete(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("admin"),
|
||||||
|
deleteImageFromCloudinary
|
||||||
|
);
|
||||||
|
export default router;
|
Loading…
Reference in New Issue
Block a user