Merge branch 'master' of http://128.199.30.231/possibillion/smellika-api
This commit is contained in:
commit
939b3ed996
4
app.js
4
app.js
@ -161,6 +161,8 @@ import SeoRoute from "./resources/SEO&Analytics/SEORouter.js";
|
|||||||
|
|
||||||
//Affiliate Routes
|
//Affiliate Routes
|
||||||
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
||||||
|
//Blog Routes
|
||||||
|
import BlogRoute from "./resources/Blog/BlogRoute.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
|
||||||
@ -218,6 +220,8 @@ app.use("/api/v1/affiliate", AffiliateRoute);
|
|||||||
|
|
||||||
//Coupons
|
//Coupons
|
||||||
app.use("/api/v1/coupon", CouponRoute);
|
app.use("/api/v1/coupon", CouponRoute);
|
||||||
|
//Blog
|
||||||
|
app.use("/api/v1/blog", BlogRoute);
|
||||||
//config specialty
|
//config specialty
|
||||||
// app.use("/api/config/specialty", SpecialtiesRouter);
|
// app.use("/api/config/specialty", SpecialtiesRouter);
|
||||||
//specialties
|
//specialties
|
||||||
|
63
resources/Blog/BlogController.js
Normal file
63
resources/Blog/BlogController.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import Blog from "./BlogModel.js";
|
||||||
|
|
||||||
|
export const createBlog = async (req, res) => {
|
||||||
|
const { title, tags, image, blog_content } = req.body;
|
||||||
|
console.log(req.body);
|
||||||
|
|
||||||
|
// Checking Fields
|
||||||
|
if (!title || !tags || !image || !blog_content) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: "All fields are mandatory",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let images = [];
|
||||||
|
let Allfiles = req.files.image;
|
||||||
|
console.log(Allfiles);
|
||||||
|
// if (!Array.isArray(Allfiles)) {
|
||||||
|
// Allfiles = [Allfiles]; // Convert to array if it's not already
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Allfiles.forEach((file) => {
|
||||||
|
// if (typeof file.tempFilePath === "string") {
|
||||||
|
// let filepath = file.tempFilePath;
|
||||||
|
// images.push(filepath);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const newBlog = await Blog.create({
|
||||||
|
// title,
|
||||||
|
// tags,
|
||||||
|
// image: images, // Assign the array of image file paths
|
||||||
|
// blog_content,
|
||||||
|
// });
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
message: "Blog created successfully",
|
||||||
|
data: images,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error creating blog:", error);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Internal server error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const getAllBlog = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const saveData = await Blog.find();
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: saveData,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
28
resources/Blog/BlogModel.js
Normal file
28
resources/Blog/BlogModel.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const blogSchema = new Schema(
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: [true, "Title is required"],
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
type: [String],
|
||||||
|
required: [true, "Tags are required"],
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
blog_content: {
|
||||||
|
type: Object,
|
||||||
|
required: [true, "Content is required"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const Blog = model("Blog", blogSchema);
|
||||||
|
|
||||||
|
export default Blog;
|
11
resources/Blog/BlogRoute.js
Normal file
11
resources/Blog/BlogRoute.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import express from "express";
|
||||||
|
|
||||||
|
import { createBlog, getAllBlog } from "./BlogController.js";
|
||||||
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.post("/create", createBlog);
|
||||||
|
router.get("/getallblog", getAllBlog);
|
||||||
|
|
||||||
|
export default router;
|
5
resources/Blog/dummy.json
Normal file
5
resources/Blog/dummy.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"title": "String0"
|
||||||
|
}
|
||||||
|
]
|
@ -51,15 +51,23 @@ export const getTermsAndCondition = async (req, res) => {
|
|||||||
export const updateTermsAndConditions = async (req, res) => {
|
export const updateTermsAndConditions = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
// new content
|
||||||
const { content } = req.body;
|
const { content } = req.body;
|
||||||
const termsAndCondition = await TermsAndCondition.findOneAndUpdate(
|
|
||||||
{
|
// id of the terms and conndition document
|
||||||
addedBy: req.user._id,
|
const id = req.query.id;
|
||||||
},
|
|
||||||
{
|
// object for updated terms and conndition data
|
||||||
|
const updatedTermsData = {
|
||||||
termsAndContionContent: content,
|
termsAndContionContent: content,
|
||||||
|
addedBy: req.user._id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the terms and conndition in database
|
||||||
|
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
|
||||||
|
{ _id: id },
|
||||||
|
{ $set: updatedTermsData },
|
||||||
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
@ -80,23 +88,10 @@ export const RefundPolicy = async (req, res) => {
|
|||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
// console.log(req?.user)
|
||||||
const { content } = req.body;
|
const { content } = req.body;
|
||||||
const findv = await Refundpolicy.findOne();
|
const refundPolicy = await Refundpolicy.create({
|
||||||
let refundPolicy;
|
|
||||||
if (findv) {
|
|
||||||
refundPolicy = await Refundpolicy.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
addedBy: req.user._id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Refundpolicy: content,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
refundPolicy = await Refundpolicy.create({
|
|
||||||
addedBy: req.user._id,
|
addedBy: req.user._id,
|
||||||
Refundpolicy: content,
|
Refundpolicy: content,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -130,6 +125,42 @@ export const getRefundPolicy = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// update refund policy
|
||||||
|
export const updateRefundPolicy = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
|
const {content} = req.body;
|
||||||
|
// id of the refund policy document
|
||||||
|
const id = req.query.id;
|
||||||
|
|
||||||
|
// object for updated refund policy data
|
||||||
|
const updatedRefundPolicyData = {
|
||||||
|
Refundpolicy: content,
|
||||||
|
addedBy: req.user._id
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the refund policy in database
|
||||||
|
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
|
||||||
|
{ _id: id },
|
||||||
|
{ $set: updatedRefundPolicyData },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
refundPolicy,
|
||||||
|
message: "updated successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Privacy policy controller functions
|
// Privacy policy controller functions
|
||||||
|
|
||||||
export const AddPrivacyAndPolicy = async (req, res) => {
|
export const AddPrivacyAndPolicy = async (req, res) => {
|
||||||
@ -180,15 +211,24 @@ export const getPrivacyPolicy = async (req, res) => {
|
|||||||
export const updatePrivacyPolicy = async (req, res) => {
|
export const updatePrivacyPolicy = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
|
||||||
|
// new content
|
||||||
const { content } = req.body;
|
const { content } = req.body;
|
||||||
const privacyAndPolicy = await PrivacyAndPolicy.findOneAndUpdate(
|
|
||||||
{
|
// id of the privacy policy document
|
||||||
addedBy: req.user._id,
|
const id = req.query.id;
|
||||||
},
|
|
||||||
{
|
// object for updated privacy policy data
|
||||||
|
const updatedPrivacyPolicyData = {
|
||||||
privacyAndPolicyContent: content,
|
privacyAndPolicyContent: content,
|
||||||
|
addedBy: req.user._id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the privacy policy in database
|
||||||
|
const privacyAndPolicy = await PrivacyAndPolicy.findByIdAndUpdate(
|
||||||
|
{ _id: id },
|
||||||
|
{ $set: updatedPrivacyPolicyData },
|
||||||
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
@ -254,15 +294,23 @@ export const getShipping = async (req, res) => {
|
|||||||
export const updateShipping = async (req, res) => {
|
export const updateShipping = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
// new content
|
||||||
const { content } = req.body;
|
const { content } = req.body;
|
||||||
const shipping = await Shipping.findOneAndUpdate(
|
|
||||||
{
|
// id of the shipping policy document
|
||||||
addedBy: req.user._id,
|
const id = req.query.id;
|
||||||
},
|
|
||||||
{
|
// object for updated shipping policy data
|
||||||
|
const updatedShippingData = {
|
||||||
shippingContent: content,
|
shippingContent: content,
|
||||||
|
addedBy: req.user._id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the shipping policy in database
|
||||||
|
const shipping = await Shipping.findByIdAndUpdate(
|
||||||
|
{ _id: id },
|
||||||
|
{ $set: updatedShippingData },
|
||||||
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
updatePrivacyPolicy,
|
updatePrivacyPolicy,
|
||||||
updateShipping,
|
updateShipping,
|
||||||
updateTermsAndConditions,
|
updateTermsAndConditions,
|
||||||
|
updateRefundPolicy
|
||||||
} from "./ContentController.js";
|
} from "./ContentController.js";
|
||||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
|
|
||||||
@ -46,7 +47,10 @@ router
|
|||||||
router.route("/refund-policy").get(getRefundPolicy);
|
router.route("/refund-policy").get(getRefundPolicy);
|
||||||
router
|
router
|
||||||
.route("/refund-policy")
|
.route("/refund-policy")
|
||||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), RefundPolicy);
|
.post(isAuthenticatedUser, authorizeRoles("admin"), RefundPolicy);
|
||||||
|
router
|
||||||
|
.route("/refund-policy-update")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateRefundPolicy);
|
||||||
//
|
//
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Product } from "./ProductModel.js";
|
import { Product } from "./ProductModel.js";
|
||||||
import cloudinary from "../../Utils/cloudinary.js";
|
import cloudinary from "../../Utils/cloudinary.js";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import { CategoryModel } from "../Category/CategoryModel.js";
|
||||||
export const createProduct = async (req, res) => {
|
export const createProduct = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req.files) {
|
if (!req.files) {
|
||||||
@ -334,13 +334,20 @@ export const deleteProduct = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getProductsByCategory = async (req, res) => {
|
export const getProductsByCategory = async (req, res) => {
|
||||||
const { categoryName } = req.params; // Assuming category name is in the route
|
const { categoryName } = req.params; // Assuming category name is in the route
|
||||||
|
// console.log(categoryName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const products = await Product.find({
|
// Find the category object by name first
|
||||||
category: categoryName,
|
const category = await CategoryModel.findOne({ categoryName });
|
||||||
}).sort({ createdAt: -1 });
|
|
||||||
|
if (!category) {
|
||||||
|
throw new Error("Category not found");
|
||||||
|
}
|
||||||
|
const products = await Product.find({ category: category._id }).populate('category');
|
||||||
|
// console.log(products);
|
||||||
|
|
||||||
if (products && products.length > 0) {
|
if (products && products.length > 0) {
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
|
@ -11,15 +11,15 @@ app.use(bodyParser.raw({ type: "application/json" }));
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
//checkout Routes-------------------------//
|
//checkout Routes-------------------------//
|
||||||
router.route("/support/create/").post(isAuthenticatedUser,createSupport);
|
router.route("/support/create/").post(isAuthenticatedUser,createSupport);
|
||||||
router.route("/support/getAll/").get(getAllSupportTicket);
|
router.route("/support/getAll/").get(isAuthenticatedUser, authorizeRoles("admin"),getAllSupportTicket);
|
||||||
router.route("/support/userticket/").get(isAuthenticatedUser,getAllSupportTicketofuser);
|
router.route("/support/userticket/").get(isAuthenticatedUser,getAllSupportTicketofuser);
|
||||||
router
|
router
|
||||||
.route("/support/delete/:id")
|
.route("/support/delete/:id")
|
||||||
.delete( deleteSupport);
|
.delete( deleteSupport);
|
||||||
router.route("/support/getOne/:id").get(getOneSupportTicket);
|
router.route("/support/getOne/:id").get(isAuthenticatedUser, getOneSupportTicket);
|
||||||
router
|
router
|
||||||
.route("/support/update/:id")
|
.route("/support/update/:id")
|
||||||
.patch(updateSupport);
|
.patch(isAuthenticatedUser, updateSupport);
|
||||||
router
|
router
|
||||||
.route("/support/deleteImage/jatinMor/CustomerSupport/:public_id")
|
.route("/support/deleteImage/jatinMor/CustomerSupport/:public_id")
|
||||||
.delete(
|
.delete(
|
||||||
|
@ -3,7 +3,7 @@ import { Testimonial } from "./TestimonialModel.js";
|
|||||||
export const AddNewTestimonial = async (req, res) => {
|
export const AddNewTestimonial = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
// console.log(req?.user);
|
||||||
|
|
||||||
if (req.files) {
|
if (req.files) {
|
||||||
let getImg = req.files.image;
|
let getImg = req.files.image;
|
||||||
@ -36,8 +36,6 @@ export const AddNewTestimonial = async (req, res) => {
|
|||||||
|
|
||||||
export const FindAllTestimonial = async (req, res) => {
|
export const FindAllTestimonial = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
|
||||||
// console.log(req?.user)
|
|
||||||
|
|
||||||
const testimonial = await Testimonial.find().sort({ createdAt: -1 });
|
const testimonial = await Testimonial.find().sort({ createdAt: -1 });
|
||||||
if (testimonial) {
|
if (testimonial) {
|
||||||
@ -68,6 +66,7 @@ export const FindOneTestimonial = async (req, res) => {
|
|||||||
return res.status(400).json({ message: "please give ID !" });
|
return res.status(400).json({ message: "please give ID !" });
|
||||||
|
|
||||||
const testimonial = await Testimonial.findById(req.params.id);
|
const testimonial = await Testimonial.findById(req.params.id);
|
||||||
|
// console.log(testimonial);
|
||||||
if (testimonial) {
|
if (testimonial) {
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -82,3 +81,125 @@ export const FindOneTestimonial = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 3.update testimonials
|
||||||
|
export const updatetesTimonial = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// Check if the user is authenticated
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "Please login!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructure request body
|
||||||
|
const { name, company, testimonial } = req.body;
|
||||||
|
|
||||||
|
// Get the authenticated user's ID
|
||||||
|
const userId = req.user._id;
|
||||||
|
|
||||||
|
// Prepare an object for the updated testimonial data
|
||||||
|
const updatedTestimonialData = {
|
||||||
|
name,
|
||||||
|
company,
|
||||||
|
testimonial,
|
||||||
|
user: userId, // Assign the authenticated user's ID to the testimonial's user field
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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: "GetSygnal/Testimonial",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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 testimonial's image field
|
||||||
|
updatedTestimonialData.image = image;
|
||||||
|
}
|
||||||
|
// console.log(updatedTestimonialData);
|
||||||
|
// Update the testimonial in the database
|
||||||
|
const modifiedTestimonial = await Testimonial.findOneAndUpdate(
|
||||||
|
{ _id: req.params.id },
|
||||||
|
{ $set: updatedTestimonialData },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
ModifyTestimonial: modifiedTestimonial,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
msg: 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: "Product Deleted Successfully!!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
msg: error.message ? error.message : "Something went wrong!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//delete one Product
|
||||||
|
export const deleteTestimonial = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
if (!req.params.id)
|
||||||
|
return res.status(400).json({ message: "please give ID !" });
|
||||||
|
// console.log(req.params.id)
|
||||||
|
const gettestimonial = await Testimonial.findById(req.params.id);
|
||||||
|
// console.log(gettestimonial)
|
||||||
|
if (!gettestimonial) {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ success: false, msg: "Testimonial not Found!" });
|
||||||
|
}
|
||||||
|
// Deleting Images From Cloudinary
|
||||||
|
await cloudinary.v2.uploader.destroy(gettestimonial.image.public_id);
|
||||||
|
|
||||||
|
//-------------------------//
|
||||||
|
const testimonial = await Testimonial.findByIdAndDelete(req.params.id);
|
||||||
|
if (!testimonial) {
|
||||||
|
return res.status(404).json({ message: "Testimonial Not Found" });
|
||||||
|
}
|
||||||
|
await testimonial.remove();
|
||||||
|
res
|
||||||
|
.status(200)
|
||||||
|
.json({ success: true, msg: "Testimonial Deleted Successfully!!" });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
msg: error.message ? error.message : "Something went wrong!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -4,6 +4,9 @@ import {
|
|||||||
AddNewTestimonial,
|
AddNewTestimonial,
|
||||||
FindAllTestimonial,
|
FindAllTestimonial,
|
||||||
FindOneTestimonial,
|
FindOneTestimonial,
|
||||||
|
deleteImageFromCloudinary,
|
||||||
|
deleteTestimonial,
|
||||||
|
updatetesTimonial,
|
||||||
} from "./TestimonialController.js";
|
} from "./TestimonialController.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -11,9 +14,19 @@ const router = express.Router();
|
|||||||
router.route("/new").post(isAuthenticatedUser, AddNewTestimonial);
|
router.route("/new").post(isAuthenticatedUser, AddNewTestimonial);
|
||||||
router
|
router
|
||||||
.route("/getAll")
|
.route("/getAll")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), FindAllTestimonial);
|
.get(FindAllTestimonial);
|
||||||
router.route("/getOne/:id").get(isAuthenticatedUser, FindOneTestimonial);
|
router.route("/getOne/:id").get(isAuthenticatedUser, FindOneTestimonial);
|
||||||
|
router
|
||||||
// router.route("/product/getAll/").get(getAllProduct)
|
.route("/delete/:id")
|
||||||
|
.delete(isAuthenticatedUser, authorizeRoles("admin"), deleteTestimonial);
|
||||||
|
router
|
||||||
|
.route("/update/:id")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatetesTimonial);
|
||||||
|
router
|
||||||
|
.route("/deleteImage/GetSygnal/Testimonial/:public_id")
|
||||||
|
.delete(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("admin"),
|
||||||
|
deleteImageFromCloudinary
|
||||||
|
);
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
Reference in New Issue
Block a user