fff
This commit is contained in:
parent
1d885ea074
commit
c999f1bf81
22
.env
22
.env
@ -1,15 +1,15 @@
|
|||||||
|
|
||||||
mongodb
|
# mongodb
|
||||||
DB_URL="mongodb+srv://printsignsAdmin:dtMmP8h0AjxYpDah@cluster0.srx6va5.mongodb.net/?retryWrites=true&w=majority"
|
# DB_URL="mongodb+srv://Get-Sygnal:Doo1KHDIWWlSsTFW@cluster0.zom9mlq.mongodb.net/?retryWrites=true&w=majority"
|
||||||
|
DB_URL="mongodb+srv://Get-Sygnal:Doo1KHDIWWlSsTFW@cluster.zom9mlq.mongodb.net/test?ssl=true&sslValidate=true"
|
||||||
PORT = 8000
|
PORT = 8000
|
||||||
JWT_SECRET = jdvnvjwrniwj4562jn6@1xsbfeh@wre4Njdf;
|
JWT_SECRET = jdvnvjwrniwj4562jn6@1xsbfeh@wre4Njdf;
|
||||||
|
|
||||||
|
|
||||||
// Bolo cloudinary credential
|
# // Get-Sygnal cloudinary credential
|
||||||
CLOUDINARY_NAME = "dhkmsthix"
|
CLOUDINARY_NAME = "dne5rkqkt"
|
||||||
CLOUDINARY_API_KEY = "938923891277448"
|
CLOUDINARY_API_KEY = "335493365729323"
|
||||||
CLOUDINARY_API_SECRET = "KkjTq-3v_vZpWqiOEnnWmGf7DoM"
|
CLOUDINARY_API_SECRET = "uBPv-qUGSGBwVyUKya6tGZjrBSc"
|
||||||
|
|
||||||
# SEND_EMAIL_FROM="project.boloai@gmail.com"
|
# SEND_EMAIL_FROM="project.boloai@gmail.com"
|
||||||
|
|
||||||
@ -20,16 +20,16 @@ CLOUDINARY_API_SECRET = "KkjTq-3v_vZpWqiOEnnWmGf7DoM"
|
|||||||
# SMPT_PORT="587"
|
# SMPT_PORT="587"
|
||||||
# SMPT_MAIL="beameri.team@gmail.com"
|
# SMPT_MAIL="beameri.team@gmail.com"
|
||||||
# SMPT_PASSWORD="xsmtpsib-a88c224860249a3f1e0765e0e3d119c1bf07ad21f2859318fbf50975deee1711-JrdPpfsvF6LwEn4A"
|
# SMPT_PASSWORD="xsmtpsib-a88c224860249a3f1e0765e0e3d119c1bf07ad21f2859318fbf50975deee1711-JrdPpfsvF6LwEn4A"
|
||||||
SEND_EMAIL_FROM="Sales@thesolarsign.com"
|
SEND_EMAIL_FROM="admin@getsygnal.com"
|
||||||
|
|
||||||
# Bolo Ai
|
# Bolo Ai
|
||||||
SENDGRID_API_KEY="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"
|
SENDGRID_API_KEY="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"
|
||||||
|
|
||||||
SMPT_HOST="smtp-relay.brevo.com"
|
SMPT_HOST="smtp-relay.brevo.com"
|
||||||
SMPT_PORT="587"
|
SMPT_PORT="587"
|
||||||
SMPT_MAIL="polytek01@yahoo.com"
|
SMPT_MAIL=" admin@getsygnal.com"
|
||||||
SMPT_PASSWORD="254GT9dQngVKIFHz"
|
SMPT_PASSWORD="j15Jb8UzhmMx07pN"
|
||||||
# SMPT_PASSWORD="CBNyJ4bZ3XR1IUDc"
|
# SMPT_PASSWORD="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"
|
||||||
|
|
||||||
PAYPAL_CLIENT_ID="AemCjVuWswklp1sWUo4peCFg9eS4bofMsMR0RCrVRB2DifYR1IUSrWqtHpVmQlrVMKTI2cWZXLJAdYwn"
|
PAYPAL_CLIENT_ID="AemCjVuWswklp1sWUo4peCFg9eS4bofMsMR0RCrVRB2DifYR1IUSrWqtHpVmQlrVMKTI2cWZXLJAdYwn"
|
||||||
PAYPAL_CLIENT_SECRET="EAo0Y9ff3jpHHg1QAbftdebfh7cb_-vnebhQrP9KALbCVer908yx2tO2eHO39r7EJSfqc4D69Qgx8R31"
|
PAYPAL_CLIENT_SECRET="EAo0Y9ff3jpHHg1QAbftdebfh7cb_-vnebhQrP9KALbCVer908yx2tO2eHO39r7EJSfqc4D69Qgx8R31"
|
@ -1,21 +1,18 @@
|
|||||||
import cloudinary from "cloudinary";
|
import cloudinary from "cloudinary";
|
||||||
import { CloudinaryStorage } from "multer-storage-cloudinary";
|
import { CloudinaryStorage } from "multer-storage-cloudinary";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import path from "path"
|
import path from "path";
|
||||||
cloudinary.v2.config({
|
cloudinary.v2.config({
|
||||||
cloud_name: process.env.CLOUDINARY_NAME,
|
cloud_name: process.env.CLOUDINARY_NAME,
|
||||||
api_key: process.env.CLOUDINARY_API_KEY,
|
api_key: process.env.CLOUDINARY_API_KEY,
|
||||||
api_secret: process.env.CLOUDINARY_API_SECRET,
|
api_secret: process.env.CLOUDINARY_API_SECRET,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const storage = new CloudinaryStorage({
|
const storage = new CloudinaryStorage({
|
||||||
cloudinary: cloudinary,
|
cloudinary: cloudinary,
|
||||||
params: {
|
params: {
|
||||||
folder: "Atp",
|
folder: "GetSygnal",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// export const upload = multer({
|
// export const upload = multer({
|
||||||
@ -30,18 +27,16 @@ const storage = new CloudinaryStorage({
|
|||||||
// },
|
// },
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const upload = multer({
|
export const upload = multer({
|
||||||
storage: multer.diskStorage({}),
|
storage: multer.diskStorage({}),
|
||||||
fileFilter: (req, file, cb) => {
|
fileFilter: (req, file, cb) => {
|
||||||
let ext = path.extname(file.originalname);
|
let ext = path.extname(file.originalname);
|
||||||
if (ext !== ".jpg" && ext !== ".jpeg" && ext !== ".png") {
|
if (ext !== ".jpg" && ext !== ".jpeg" && ext !== ".png") {
|
||||||
cb(new Error("File type not supported!"), false)
|
cb(new Error("File type not supported!"), false);
|
||||||
return
|
return;
|
||||||
}
|
|
||||||
cb(null, true);
|
|
||||||
}
|
}
|
||||||
|
cb(null, true);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default cloudinary;
|
export default cloudinary;
|
||||||
|
@ -13,176 +13,176 @@
|
|||||||
import cloudinary from "./cloudinary.js";
|
import cloudinary from "./cloudinary.js";
|
||||||
|
|
||||||
const getEntities = async (
|
const getEntities = async (
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
Entity,
|
Entity,
|
||||||
isUser = false,
|
isUser = false,
|
||||||
criteria = false,
|
criteria = false,
|
||||||
log = false
|
log = false
|
||||||
) => {
|
) => {
|
||||||
//pagination added filter can change so it needs to be dynamic will add it in future
|
//pagination added filter can change so it needs to be dynamic will add it in future
|
||||||
let { page, limit } = req.query;
|
let { page, limit } = req.query;
|
||||||
page = page * 1;
|
page = page * 1;
|
||||||
limit = limit * 1;
|
limit = limit * 1;
|
||||||
let limitVal = limit;
|
let limitVal = limit;
|
||||||
let skipeValue = (page - 1) * limitVal;
|
let skipeValue = (page - 1) * limitVal;
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
if (!req.user) return res.status(400).json({ message: "User not found." });
|
if (!req.user) return res.status(400).json({ message: "User not found." });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (criteria) {
|
if (criteria) {
|
||||||
const entity = await Entity.find({ createdBy: req.user._id });
|
const entity = await Entity.find({ createdBy: req.user._id });
|
||||||
return res.status(200).json({ status: "OK", data: entity });
|
return res.status(200).json({ status: "OK", data: entity });
|
||||||
}
|
|
||||||
const totalRecords = await Entity.countDocuments({});
|
|
||||||
const entity = await Entity.find({})
|
|
||||||
.sort({ createdAt: -1 })
|
|
||||||
.limit(limitVal)
|
|
||||||
.skip(skipeValue);
|
|
||||||
res
|
|
||||||
.status(200)
|
|
||||||
.json({ status: "OK", totalRecords: totalRecords, data: entity });
|
|
||||||
} catch (err) {
|
|
||||||
log && console.log(err);
|
|
||||||
return res.status(500).json({ message: "Unable to fetch." });
|
|
||||||
}
|
}
|
||||||
|
const totalRecords = await Entity.countDocuments({});
|
||||||
|
const entity = await Entity.find({})
|
||||||
|
.sort({ createdAt: -1 })
|
||||||
|
.limit(limitVal)
|
||||||
|
.skip(skipeValue);
|
||||||
|
res
|
||||||
|
.status(200)
|
||||||
|
.json({ status: "OK", totalRecords: totalRecords, data: entity });
|
||||||
|
} catch (err) {
|
||||||
|
log && console.log(err);
|
||||||
|
return res.status(500).json({ message: "Unable to fetch." });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEntity = async (req, res, Entity, isUser = false, log = false) => {
|
const getEntity = async (req, res, Entity, isUser = false, log = false) => {
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
1;
|
1;
|
||||||
if (!req.user) return res.status(400).json({ message: "User not found." });
|
if (!req.user) return res.status(400).json({ message: "User not found." });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const entity = await Entity.findById(req.params.id);
|
const entity = await Entity.findById(req.params.id);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
return res.status(400).json({ message: "Not found" });
|
return res.status(400).json({ message: "Not found" });
|
||||||
}
|
|
||||||
res.status(200).json({ status: "OK", data: entity });
|
|
||||||
} catch (err) {
|
|
||||||
log && console.log(err);
|
|
||||||
return res.status(500).json({ message: "Unable to find" });
|
|
||||||
}
|
}
|
||||||
|
res.status(200).json({ status: "OK", data: entity });
|
||||||
|
} catch (err) {
|
||||||
|
log && console.log(err);
|
||||||
|
return res.status(500).json({ message: "Unable to find" });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const addEntity = async (
|
const addEntity = async (
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
Entity,
|
Entity,
|
||||||
isUser = false,
|
isUser = false,
|
||||||
isSingleImage = false,
|
isSingleImage = false,
|
||||||
isMultipleImages = false,
|
isMultipleImages = false,
|
||||||
isCreatedBy = false,
|
isCreatedBy = false,
|
||||||
log = false
|
log = false
|
||||||
) => {
|
) => {
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
if (!req.user) return res.status(400).json({ message: "User not found." });
|
if (!req.user) return res.status(400).json({ message: "User not found." });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (isCreatedBy) {
|
||||||
|
req.body.createdBy = req.user._id;
|
||||||
}
|
}
|
||||||
try {
|
if (isSingleImage) {
|
||||||
if (isCreatedBy) {
|
if (req.file) {
|
||||||
req.body.createdBy = req.user._id;
|
const result = await cloudinary.v2.uploader.upload(req.file.path);
|
||||||
}
|
const image = { url: result.secure_url, public_id: result.public_id };
|
||||||
if (isSingleImage) {
|
req.body.image = image;
|
||||||
if (req.file) {
|
}
|
||||||
const result = await cloudinary.v2.uploader.upload(req.file.path);
|
|
||||||
const image = { url: result.secure_url, public_id: result.public_id };
|
|
||||||
req.body.image = image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isMultipleImages) {
|
|
||||||
const imageUrlList = [];
|
|
||||||
for (var i = 0; i < req.files.length; i++) {
|
|
||||||
const locaFilePath = req.files[i].path;
|
|
||||||
const result = await cloudinary.v2.uploader.upload(locaFilePath);
|
|
||||||
imageUrlList.push({ url: result.url, public_id: result.public_id });
|
|
||||||
}
|
|
||||||
req.body.files = imageUrlList;
|
|
||||||
}
|
|
||||||
const entity = await Entity.create(req.body);
|
|
||||||
res.status(200).json({ status: "OK", data: entity });
|
|
||||||
} catch (err) {
|
|
||||||
log && console.log(err);
|
|
||||||
return res.status(500).json({ message: "Unable to create." });
|
|
||||||
}
|
}
|
||||||
|
if (isMultipleImages) {
|
||||||
|
const imageUrlList = [];
|
||||||
|
for (var i = 0; i < req.files.length; i++) {
|
||||||
|
const locaFilePath = req.files[i].path;
|
||||||
|
const result = await cloudinary.v2.uploader.upload(locaFilePath);
|
||||||
|
imageUrlList.push({ url: result.url, public_id: result.public_id });
|
||||||
|
}
|
||||||
|
req.body.files = imageUrlList;
|
||||||
|
}
|
||||||
|
const entity = await Entity.create(req.body);
|
||||||
|
res.status(200).json({ status: "OK", data: entity });
|
||||||
|
} catch (err) {
|
||||||
|
log && console.log(err);
|
||||||
|
return res.status(500).json({ message: "Unable to create." });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateEntity = async (
|
const updateEntity = async (
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
Entity,
|
Entity,
|
||||||
isUser = false,
|
isUser = false,
|
||||||
isSingleImage = false,
|
isSingleImage = false,
|
||||||
isMultipleImages = false,
|
isMultipleImages = false,
|
||||||
log = false
|
log = false
|
||||||
) => {
|
) => {
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
if (!req.user) return res.status(400).json({ message: "User not found." });
|
if (!req.user) return res.status(400).json({ message: "User not found." });
|
||||||
|
}
|
||||||
|
let entity = await Entity.findById(req.params.id);
|
||||||
|
if (!entity) {
|
||||||
|
return res.status(400).json({ message: "Not found" });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (isSingleImage) {
|
||||||
|
await cloudinary.v2.uploader.destroy(req.body.public_id);
|
||||||
|
if (req.file) {
|
||||||
|
const result = await cloudinary.v2.uploader.upload(req.file.path);
|
||||||
|
const image = { url: result.url, public_id: result.public_id };
|
||||||
|
req.body.image = image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let entity = await Entity.findById(req.params.id);
|
if (isMultipleImages) {
|
||||||
if (!entity) {
|
for (let i = 0; i < req.body.publicIdArray; i++) {
|
||||||
return res.status(400).json({ message: "Not found" });
|
await cloudinary.v2.uploader.destroy(req.body.publicIdArray[i]);
|
||||||
}
|
}
|
||||||
try {
|
const imageUrlList = [];
|
||||||
if (isSingleImage) {
|
for (var i = 0; i < req.files.length; i++) {
|
||||||
await cloudinary.v2.uploader.destroy(req.body.public_id);
|
const locaFilePath = req.files[i].path;
|
||||||
if (req.file) {
|
const result = await cloudinary.v2.uploader.upload(locaFilePath);
|
||||||
const result = await cloudinary.v2.uploader.upload(req.file.path);
|
imageUrlList.push({ url: result.url, public_id: result.public_id });
|
||||||
const image = { url: result.url, public_id: result.public_id };
|
}
|
||||||
req.body.image = image;
|
req.body.files = imageUrlList;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isMultipleImages) {
|
|
||||||
for (let i = 0; i < req.body.publicIdArray; i++) {
|
|
||||||
await cloudinary.v2.uploader.destroy(req.body.publicIdArray[i]);
|
|
||||||
}
|
|
||||||
const imageUrlList = [];
|
|
||||||
for (var i = 0; i < req.files.length; i++) {
|
|
||||||
const locaFilePath = req.files[i].path;
|
|
||||||
const result = await cloudinary.v2.uploader.upload(locaFilePath);
|
|
||||||
imageUrlList.push({ url: result.url, public_id: result.public_id });
|
|
||||||
}
|
|
||||||
req.body.files = imageUrlList;
|
|
||||||
}
|
|
||||||
entity = await Entity.findByIdAndUpdate(req.params.id, req.body, {
|
|
||||||
new: true,
|
|
||||||
});
|
|
||||||
res.status(200).json({ status: "OK", data: entity });
|
|
||||||
} catch (err) {
|
|
||||||
log && console.log(err);
|
|
||||||
return res.status(500).json({ message: "Unable to update." });
|
|
||||||
}
|
}
|
||||||
|
entity = await Entity.findByIdAndUpdate(req.params.id, req.body, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
res.status(200).json({ status: "OK", data: entity });
|
||||||
|
} catch (err) {
|
||||||
|
log && console.log(err);
|
||||||
|
return res.status(500).json({ message: "Unable to update." });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteEntity = async (
|
const deleteEntity = async (
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
Entity,
|
Entity,
|
||||||
isUser = false,
|
isUser = false,
|
||||||
isSingleImage = false,
|
isSingleImage = false,
|
||||||
isMultipleImages = false,
|
isMultipleImages = false,
|
||||||
log = false
|
log = false
|
||||||
) => {
|
) => {
|
||||||
if (isUser) {
|
if (isUser) {
|
||||||
if (!req.user) return res.status(400).json({ message: "User not found." });
|
if (!req.user) return res.status(400).json({ message: "User not found." });
|
||||||
}
|
}
|
||||||
// if (isSingleImage) {
|
// if (isSingleImage) {
|
||||||
// req.body.imageUrl = req.file.location;
|
// req.body.imageUrl = req.file.location;
|
||||||
|
// }
|
||||||
|
try {
|
||||||
|
// if (isSingleImage) {
|
||||||
|
// await cloudinary.v2.uploader.destroy(entity.image.public_id);
|
||||||
|
// }
|
||||||
|
// if (isMultipleImages) {
|
||||||
|
// for (let i = 0; i < entity.files.length; i++) {
|
||||||
|
// await cloudinary.v2.uploader.destroy(entity.files[i].public_id);
|
||||||
// }
|
// }
|
||||||
try {
|
// }
|
||||||
// if (isSingleImage) {
|
await Entity.deleteOne({ _id: req.params.id });
|
||||||
// await cloudinary.v2.uploader.destroy(entity.image.public_id);
|
res.status(200).json({ status: "OK", message: "Deleted Successfully" });
|
||||||
// }
|
} catch (err) {
|
||||||
// if (isMultipleImages) {
|
log && console.log(err);
|
||||||
// for (let i = 0; i < entity.files.length; i++) {
|
return res.status(500).json({ message: "Unable to delete" });
|
||||||
// await cloudinary.v2.uploader.destroy(entity.files[i].public_id);
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
await Entity.deleteOne({ _id: req.params.id });
|
|
||||||
res.status(200).json({ status: "OK", message: "Deleted Successfully" });
|
|
||||||
} catch (err) {
|
|
||||||
log && console.log(err);
|
|
||||||
return res.status(500).json({ message: "Unable to delete" });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { getEntities, getEntity, addEntity, updateEntity, deleteEntity };
|
export { getEntities, getEntity, addEntity, updateEntity, deleteEntity };
|
||||||
|
12
app.js
12
app.js
@ -53,9 +53,9 @@ import PurposeRoute from "./resources/setting/Purpose/Purpose_routes.js";
|
|||||||
// category Route
|
// category Route
|
||||||
import categoryRoute from "./resources/Category/categoryRoutes.js";
|
import categoryRoute from "./resources/Category/categoryRoutes.js";
|
||||||
import bannerRoute from "./resources/Banner/BannerRouter.js";
|
import bannerRoute from "./resources/Banner/BannerRouter.js";
|
||||||
import RegistrationImageRoute from './resources/RegistrationImage/RegistrationImageRoute.js';
|
import RegistrationImageRoute from "./resources/RegistrationImage/RegistrationImageRoute.js";
|
||||||
import loginImageRoute from './resources/LoginImage/LoginImageRoute.js'
|
import loginImageRoute from "./resources/LoginImage/LoginImageRoute.js";
|
||||||
import shopImageRoute from './resources/ShopPageImage/ShopPageImageRoute.js'
|
import shopImageRoute from "./resources/ShopPageImage/ShopPageImageRoute.js";
|
||||||
import ContentRoute from "./resources/Content/ContentRoutes.js";
|
import ContentRoute from "./resources/Content/ContentRoutes.js";
|
||||||
import UserAddressRoute from "./resources/userAddress/useAddressRoute.js";
|
import UserAddressRoute from "./resources/userAddress/useAddressRoute.js";
|
||||||
//business_Type
|
//business_Type
|
||||||
@ -83,9 +83,9 @@ app.use("/api", ProductRouter);
|
|||||||
app.use("/api/category", categoryRoute);
|
app.use("/api/category", categoryRoute);
|
||||||
app.use("/api/banner", bannerRoute);
|
app.use("/api/banner", bannerRoute);
|
||||||
// registration image
|
// registration image
|
||||||
app.use('/api/registerImage', RegistrationImageRoute)
|
app.use("/api/registerImage", RegistrationImageRoute);
|
||||||
app.use('/api/loginImage', loginImageRoute)
|
app.use("/api/loginImage", loginImageRoute);
|
||||||
app.use('/api/shopImage', shopImageRoute)
|
app.use("/api/shopImage", shopImageRoute);
|
||||||
// Content
|
// Content
|
||||||
app.use("/api/content", ContentRoute);
|
app.use("/api/content", ContentRoute);
|
||||||
// User Address
|
// User Address
|
||||||
|
@ -17,7 +17,7 @@ export const addBanner = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
bannerImage.tempFilePath,
|
bannerImage.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/banner",
|
folder: "GetSygnal/banner",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ export const updateBanner = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
bannerImag.tempFilePath,
|
bannerImag.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/banner",
|
folder: "GetSygnal/banner",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const update = await BannerModel.findOneAndUpdate(
|
const update = await BannerModel.findOneAndUpdate(
|
||||||
|
@ -16,7 +16,7 @@ export const addCategory = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
categoryImage.tempFilePath,
|
categoryImage.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/category",
|
folder: "GetSygnal/category",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export const updateCategory = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
categoryImag.tempFilePath,
|
categoryImag.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/category",
|
folder: "GetSygnal/category",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const update = await CategoryModel.findOneAndUpdate(
|
const update = await CategoryModel.findOneAndUpdate(
|
||||||
|
@ -41,7 +41,7 @@ const imageUpload = multer({ storage: imageStorage }).any();
|
|||||||
// const result = await cloudinary.v2.uploader.upload(
|
// const result = await cloudinary.v2.uploader.upload(
|
||||||
// designImage.tempFilePath,
|
// designImage.tempFilePath,
|
||||||
// {
|
// {
|
||||||
// folder: "jatinMor/design",
|
// folder: "GetSygnal/design",
|
||||||
// }
|
// }
|
||||||
// );
|
// );
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ export const updateDesign = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
designImage.tempFilePath,
|
designImage.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/design",
|
folder: "GetSygnal/design",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const update = await DesignModel.findOneAndUpdate(
|
const update = await DesignModel.findOneAndUpdate(
|
||||||
|
@ -18,7 +18,7 @@ export const addImage = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
bannerImage.tempFilePath,
|
bannerImage.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/loginImage",
|
folder: "GetSygnal/loginImage",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ export const getImage = async (req, res) => {
|
|||||||
// const result = await cloudinary.v2.uploader.upload(
|
// const result = await cloudinary.v2.uploader.upload(
|
||||||
// bannerImag.tempFilePath,
|
// bannerImag.tempFilePath,
|
||||||
// {
|
// {
|
||||||
// folder: "jatinMor/loginImage",
|
// folder: "GetSygnal/loginImage",
|
||||||
// }
|
// }
|
||||||
// );
|
// );
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ export const updateImage = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
bannerImag.tempFilePath,
|
bannerImag.tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/loginImage",
|
folder: "GetSygnal/loginImage",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
console.log("result", result);
|
console.log("result", result);
|
||||||
|
@ -24,7 +24,7 @@ export const createProduct = async (req, res) => {
|
|||||||
const imagesLinks = [];
|
const imagesLinks = [];
|
||||||
for (let i = 0; i < images.length; i++) {
|
for (let i = 0; i < images.length; i++) {
|
||||||
const result = await cloudinary.v2.uploader.upload(images[i], {
|
const result = await cloudinary.v2.uploader.upload(images[i], {
|
||||||
folder: "jatinMor/product",
|
folder: "GetSygnal/product",
|
||||||
});
|
});
|
||||||
|
|
||||||
imagesLinks.push({
|
imagesLinks.push({
|
||||||
@ -112,7 +112,7 @@ export const updateProduct = async (req, res) => {
|
|||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
newuploadImages[i].tempFilePath,
|
newuploadImages[i].tempFilePath,
|
||||||
{
|
{
|
||||||
folder: "jatinMor/product",
|
folder: "GetSygnal/product",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -5,60 +5,60 @@ import { RegistrationImageModel } from "./RegistrationImageModel.js";
|
|||||||
|
|
||||||
// Add new Category
|
// Add new Category
|
||||||
export const addImage = async (req, res) => {
|
export const addImage = async (req, res) => {
|
||||||
// const { bannerName } = req.body;
|
// const { bannerName } = req.body;
|
||||||
const { bannerImage } = req.files;
|
const { bannerImage } = req.files;
|
||||||
// console.log("image", bannerImage);
|
// console.log("image", bannerImage);
|
||||||
// console.log(categoryName, categoryImage);
|
// console.log(categoryName, categoryImage);
|
||||||
|
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
try {
|
try {
|
||||||
if (!mongoose.Types.ObjectId.isValid(req.user._id)) {
|
if (!mongoose.Types.ObjectId.isValid(req.user._id)) {
|
||||||
return res.status(400).json({ message: "please login again " });
|
return res.status(400).json({ message: "please login again " });
|
||||||
}
|
|
||||||
const result = await cloudinary.v2.uploader.upload(
|
|
||||||
bannerImage.tempFilePath,
|
|
||||||
{
|
|
||||||
folder: "jatinMor/registrationImage",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
const regsiterImage = await RegistrationImageModel.create({
|
|
||||||
image: result,
|
|
||||||
addedBy: req.user._id,
|
|
||||||
});
|
|
||||||
if (regsiterImage) {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ success: true, regsiterImage, message: "Image Added" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went Wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
bannerImage.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "GetSygnal/registrationImage",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const regsiterImage = await RegistrationImageModel.create({
|
||||||
|
image: result,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
if (regsiterImage) {
|
||||||
|
return res
|
||||||
|
.status(201)
|
||||||
|
.json({ success: true, regsiterImage, message: "Image Added" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getImage = async (req, res) => {
|
export const getImage = 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 !" });
|
||||||
const image = await RegistrationImageModel.find().sort({
|
const image = await RegistrationImageModel.find().sort({
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return res.status(404).json({ message: "No categories found" });
|
return res.status(404).json({ message: "No categories found" });
|
||||||
}
|
|
||||||
// console.log("image", image);
|
|
||||||
res.status(200).json({ success: true, image });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// console.log("image", image);
|
||||||
|
res.status(200).json({ success: true, image });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// export const updateImage = async (req, res) => {
|
// export const updateImage = async (req, res) => {
|
||||||
// try {
|
// try {
|
||||||
@ -84,7 +84,7 @@ export const getImage = async (req, res) => {
|
|||||||
// const result = await cloudinary.v2.uploader.upload(
|
// const result = await cloudinary.v2.uploader.upload(
|
||||||
// bannerImag.tempFilePath,
|
// bannerImag.tempFilePath,
|
||||||
// {
|
// {
|
||||||
// folder: "jatinMor/registrationImage",
|
// folder: "GetSygnal/registrationImage",
|
||||||
// }
|
// }
|
||||||
// );
|
// );
|
||||||
|
|
||||||
@ -124,98 +124,101 @@ export const getImage = async (req, res) => {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
export const updateImage = async (req, res) => {
|
export const updateImage = 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 !" });
|
||||||
const { _id } = req.params;
|
const { _id } = req.params;
|
||||||
const { bannerName } = req.body;
|
const { bannerName } = req.body;
|
||||||
const olderImage = req.body?.olderImage;
|
const olderImage = req.body?.olderImage;
|
||||||
const bannerImag = req.files?.bannerImage;
|
const bannerImag = req.files?.bannerImage;
|
||||||
// console.log("bannerImag", bannerImag);
|
// console.log("bannerImag", bannerImag);
|
||||||
|
|
||||||
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
||||||
return res.status(404).json({ error: "Can not find the document " });
|
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 RegistrationImageModel.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: "jatinMor/registrationImage",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
console.log("result", result);
|
|
||||||
const update = await RegistrationImageModel.findOneAndUpdate(
|
|
||||||
{ _id: _id },
|
|
||||||
{ image: result }, // Provide the updated categoryName
|
|
||||||
{ new: true } // To return the updated document
|
|
||||||
);
|
|
||||||
if (!update) {
|
|
||||||
return res
|
|
||||||
.status(404)
|
|
||||||
.json({ message: "Can not update document, something went wrong" });
|
|
||||||
} else {
|
|
||||||
return res.status(200).json({ success: true, update });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const update = await RegistrationImageModel.findOneAndUpdate(
|
|
||||||
{ _id: _id },
|
|
||||||
{ image: JSON.parse(olderImage) }, // Provide the updated categoryName
|
|
||||||
{ new: true } // To return the updated document
|
|
||||||
);
|
|
||||||
if (update) {
|
|
||||||
return res.status(200).json({ success: true, update });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// console.log(JSON.parse(olderImage).length);
|
||||||
|
// find the document with the id to delete the image from cloudinary
|
||||||
|
|
||||||
|
if (olderImage) {
|
||||||
|
const deletefromCloudinary = await RegistrationImageModel.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/registrationImage",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log("result", result);
|
||||||
|
const update = await RegistrationImageModel.findOneAndUpdate(
|
||||||
|
{ _id: _id },
|
||||||
|
{ image: result }, // Provide the updated categoryName
|
||||||
|
{ new: true } // To return the updated document
|
||||||
|
);
|
||||||
|
if (!update) {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ message: "Can not update document, something went wrong" });
|
||||||
|
} else {
|
||||||
|
return res.status(200).json({ success: true, update });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const update = await RegistrationImageModel.findOneAndUpdate(
|
||||||
|
{ _id: _id },
|
||||||
|
{ image: JSON.parse(olderImage) }, // Provide the updated categoryName
|
||||||
|
{ new: true } // To return the updated document
|
||||||
|
);
|
||||||
|
if (update) {
|
||||||
|
return res.status(200).json({ success: true, update });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteImage = async (req, res) => {
|
export const deleteImage = 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 !" });
|
||||||
const { _id } = req.params;
|
const { _id } = req.params;
|
||||||
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
||||||
return res.status(404).json({ error: "Can not find the document " });
|
return res.status(404).json({ error: "Can not find the document " });
|
||||||
}
|
|
||||||
|
|
||||||
const deletefromCloudinary = await RegistrationImageModel.findOne({ _id: _id });
|
|
||||||
// console.log(deletefromCloudinary);
|
|
||||||
const deleteresponse = await cloudinary.v2.uploader.destroy(
|
|
||||||
deletefromCloudinary.image.public_id
|
|
||||||
);
|
|
||||||
if (deleteresponse) {
|
|
||||||
const deleteBanner = await RegistrationImageModel.findOneAndDelete({ _id: _id });
|
|
||||||
if (!deleteBanner) {
|
|
||||||
return res.status(404).json({
|
|
||||||
error: "Can not find the document with the provided id to delete ",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
res.status(200).json({ success: true, deleteBanner });
|
|
||||||
} else {
|
|
||||||
return res.status(404).json({ error: "can not delete the banner " });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deletefromCloudinary = await RegistrationImageModel.findOne({
|
||||||
|
_id: _id,
|
||||||
|
});
|
||||||
|
// console.log(deletefromCloudinary);
|
||||||
|
const deleteresponse = await cloudinary.v2.uploader.destroy(
|
||||||
|
deletefromCloudinary.image.public_id
|
||||||
|
);
|
||||||
|
if (deleteresponse) {
|
||||||
|
const deleteBanner = await RegistrationImageModel.findOneAndDelete({
|
||||||
|
_id: _id,
|
||||||
|
});
|
||||||
|
if (!deleteBanner) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: "Can not find the document with the provided id to delete ",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(200).json({ success: true, deleteBanner });
|
||||||
|
} else {
|
||||||
|
return res.status(404).json({ error: "can not delete the banner " });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -3,64 +3,62 @@ import mongoose from "mongoose";
|
|||||||
import cloudinary from "../../Utils/cloudinary.js";
|
import cloudinary from "../../Utils/cloudinary.js";
|
||||||
import { ShopPageImageModel } from "./ShopPageImageModel.js";
|
import { ShopPageImageModel } from "./ShopPageImageModel.js";
|
||||||
|
|
||||||
|
// Add new Category
|
||||||
|
|
||||||
// Add new Category
|
|
||||||
export const addImage = async (req, res) => {
|
export const addImage = async (req, res) => {
|
||||||
// const { bannerName } = req.body;
|
// const { bannerName } = req.body;
|
||||||
const { bannerImage } = req.files;
|
const { bannerImage } = req.files;
|
||||||
// console.log("image", bannerImage);
|
// console.log("image", bannerImage);
|
||||||
// console.log(categoryName, categoryImage);
|
// console.log(categoryName, categoryImage);
|
||||||
|
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
try {
|
try {
|
||||||
if (!mongoose.Types.ObjectId.isValid(req.user._id)) {
|
if (!mongoose.Types.ObjectId.isValid(req.user._id)) {
|
||||||
return res.status(400).json({ message: "please login again " });
|
return res.status(400).json({ message: "please login again " });
|
||||||
}
|
|
||||||
const result = await cloudinary.v2.uploader.upload(
|
|
||||||
bannerImage.tempFilePath,
|
|
||||||
{
|
|
||||||
folder: "jatinMor/shopImage",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
const regsiterImage = await ShopPageImageModel.create({
|
|
||||||
image: result,
|
|
||||||
addedBy: req.user._id,
|
|
||||||
});
|
|
||||||
if (regsiterImage) {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ success: true, regsiterImage, message: "Image Added" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went Wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
|
bannerImage.tempFilePath,
|
||||||
|
{
|
||||||
|
folder: "GetSygnal/shopImage",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const regsiterImage = await ShopPageImageModel.create({
|
||||||
|
image: result,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
if (regsiterImage) {
|
||||||
|
return res
|
||||||
|
.status(201)
|
||||||
|
.json({ success: true, regsiterImage, message: "Image Added" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getImage = async (req, res) => {
|
export const getImage = 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 !" });
|
||||||
const image = await ShopPageImageModel.find().sort({
|
const image = await ShopPageImageModel.find().sort({
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return res.status(404).json({ message: "No categories found" });
|
return res.status(404).json({ message: "No categories found" });
|
||||||
}
|
|
||||||
// console.log("image", image);
|
|
||||||
res.status(200).json({ success: true, image });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// console.log("image", image);
|
||||||
|
res.status(200).json({ success: true, image });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// export const updateImage = async (req, res) => {
|
// export const updateImage = async (req, res) => {
|
||||||
// try {
|
// try {
|
||||||
@ -86,7 +84,7 @@ export const getImage = async (req, res) => {
|
|||||||
// const result = await cloudinary.v2.uploader.upload(
|
// const result = await cloudinary.v2.uploader.upload(
|
||||||
// bannerImag.tempFilePath,
|
// bannerImag.tempFilePath,
|
||||||
// {
|
// {
|
||||||
// folder: "jatinMor/shopImage",
|
// folder: "GetSygnal/shopImage",
|
||||||
// }
|
// }
|
||||||
// );
|
// );
|
||||||
|
|
||||||
@ -126,98 +124,99 @@ export const getImage = async (req, res) => {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
export const updateImage = async (req, res) => {
|
export const updateImage = 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 !" });
|
||||||
const { _id } = req.params;
|
const { _id } = req.params;
|
||||||
const { bannerName } = req.body;
|
const { bannerName } = req.body;
|
||||||
const olderImage = req.body?.olderImage;
|
const olderImage = req.body?.olderImage;
|
||||||
const bannerImag = req.files?.bannerImage;
|
const bannerImag = req.files?.bannerImage;
|
||||||
// console.log("bannerImag", bannerImag);
|
// console.log("bannerImag", bannerImag);
|
||||||
|
|
||||||
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
||||||
return res.status(404).json({ error: "Can not find the document " });
|
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 ShopPageImageModel.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: "jatinMor/shopImage",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
console.log("result", result);
|
|
||||||
const update = await ShopPageImageModel.findOneAndUpdate(
|
|
||||||
{ _id: _id },
|
|
||||||
{ image: result }, // Provide the updated categoryName
|
|
||||||
{ new: true } // To return the updated document
|
|
||||||
);
|
|
||||||
if (!update) {
|
|
||||||
return res
|
|
||||||
.status(404)
|
|
||||||
.json({ message: "Can not update document, something went wrong" });
|
|
||||||
} else {
|
|
||||||
return res.status(200).json({ success: true, update });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const update = await ShopPageImageModel.findOneAndUpdate(
|
|
||||||
{ _id: _id },
|
|
||||||
{ image: JSON.parse(olderImage) }, // Provide the updated categoryName
|
|
||||||
{ new: true } // To return the updated document
|
|
||||||
);
|
|
||||||
if (update) {
|
|
||||||
return res.status(200).json({ success: true, update });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// console.log(JSON.parse(olderImage).length);
|
||||||
|
// find the document with the id to delete the image from cloudinary
|
||||||
|
|
||||||
|
if (olderImage) {
|
||||||
|
const deletefromCloudinary = await ShopPageImageModel.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/shopImage",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log("result", result);
|
||||||
|
const update = await ShopPageImageModel.findOneAndUpdate(
|
||||||
|
{ _id: _id },
|
||||||
|
{ image: result }, // Provide the updated categoryName
|
||||||
|
{ new: true } // To return the updated document
|
||||||
|
);
|
||||||
|
if (!update) {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ message: "Can not update document, something went wrong" });
|
||||||
|
} else {
|
||||||
|
return res.status(200).json({ success: true, update });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const update = await ShopPageImageModel.findOneAndUpdate(
|
||||||
|
{ _id: _id },
|
||||||
|
{ image: JSON.parse(olderImage) }, // Provide the updated categoryName
|
||||||
|
{ new: true } // To return the updated document
|
||||||
|
);
|
||||||
|
if (update) {
|
||||||
|
return res.status(200).json({ success: true, update });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteImage = async (req, res) => {
|
export const deleteImage = 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 !" });
|
||||||
const { _id } = req.params;
|
const { _id } = req.params;
|
||||||
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
if (!mongoose.Types.ObjectId.isValid(_id)) {
|
||||||
return res.status(404).json({ error: "Can not find the document " });
|
return res.status(404).json({ error: "Can not find the document " });
|
||||||
}
|
|
||||||
|
|
||||||
const deletefromCloudinary = await ShopPageImageModel.findOne({ _id: _id });
|
|
||||||
// console.log(deletefromCloudinary);
|
|
||||||
const deleteresponse = await cloudinary.v2.uploader.destroy(
|
|
||||||
deletefromCloudinary.image.public_id
|
|
||||||
);
|
|
||||||
if (deleteresponse) {
|
|
||||||
const deleteBanner = await ShopPageImageModel.findOneAndDelete({ _id: _id });
|
|
||||||
if (!deleteBanner) {
|
|
||||||
return res.status(404).json({
|
|
||||||
error: "Can not find the document with the provided id to delete ",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
res.status(200).json({ success: true, deleteBanner });
|
|
||||||
} else {
|
|
||||||
return res.status(404).json({ error: "can not delete the banner " });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : "Something went wrong",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deletefromCloudinary = await ShopPageImageModel.findOne({ _id: _id });
|
||||||
|
// console.log(deletefromCloudinary);
|
||||||
|
const deleteresponse = await cloudinary.v2.uploader.destroy(
|
||||||
|
deletefromCloudinary.image.public_id
|
||||||
|
);
|
||||||
|
if (deleteresponse) {
|
||||||
|
const deleteBanner = await ShopPageImageModel.findOneAndDelete({
|
||||||
|
_id: _id,
|
||||||
|
});
|
||||||
|
if (!deleteBanner) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: "Can not find the document with the provided id to delete ",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(200).json({ success: true, deleteBanner });
|
||||||
|
} else {
|
||||||
|
return res.status(404).json({ error: "can not delete the banner " });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,91 +1,84 @@
|
|||||||
|
|
||||||
import cloudinary from "../../Utils/cloudinary.js";
|
import cloudinary from "../../Utils/cloudinary.js";
|
||||||
import { Testimonial } from "./TestimonialModel.js"
|
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;
|
||||||
const result = await cloudinary.v2.uploader.upload(getImg?.tempFilePath, {
|
const result = await cloudinary.v2.uploader.upload(getImg?.tempFilePath, {
|
||||||
folder: "jatinMor/Testimonial",
|
folder: "GetSygnal/Testimonial",
|
||||||
})
|
});
|
||||||
|
|
||||||
let simage = {
|
let simage = {
|
||||||
public_id: result.public_id,
|
public_id: result.public_id,
|
||||||
url: result.secure_url,
|
url: result.secure_url,
|
||||||
}
|
};
|
||||||
req.body.image = simage
|
req.body.image = simage;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
req.body.user = req.user._id
|
|
||||||
const testimonial = await Testimonial.create(req.body);
|
|
||||||
|
|
||||||
res.status(201).json({
|
|
||||||
success: true,
|
|
||||||
testimonial,
|
|
||||||
message: 'Testimonial Added',
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : 'Something went Wrong',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
req.body.user = req.user._id;
|
||||||
|
const testimonial = await Testimonial.create(req.body);
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
testimonial,
|
||||||
|
message: "Testimonial Added",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
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 !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
const testimonial = await Testimonial.find().sort({ createdAt: -1 });
|
||||||
|
if (testimonial) {
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
testimonial,
|
||||||
|
message: "Fetched All Testimonial",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: true,
|
||||||
|
|
||||||
const testimonial = await Testimonial.find().sort({ createdAt: -1 });
|
message: "No Testimonial till Now",
|
||||||
if (testimonial) {
|
});
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
testimonial,
|
|
||||||
message: 'Fetched All Testimonial',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res.status(404).json({
|
|
||||||
success: true,
|
|
||||||
|
|
||||||
message: 'No Testimonial till Now',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : 'Something went Wrong',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
export const FindOneTestimonial = async (req, res) => {
|
export const FindOneTestimonial = 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.params.id) return res.status(400).json({ message: "please give ID !" });
|
if (!req.params.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);
|
if (testimonial) {
|
||||||
if (testimonial) {
|
return res.status(200).json({
|
||||||
return res.status(200).json({
|
success: true,
|
||||||
success: true,
|
testimonial,
|
||||||
testimonial,
|
message: "Fetched Testimonial",
|
||||||
message: 'Fetched Testimonial',
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: error.message ? error.message : 'Something went Wrong',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -121,7 +121,7 @@ export const forgotPassword = async (req, res, next) => {
|
|||||||
|
|
||||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||||
|
|
||||||
subject: `The-solar-sign Password Recovery`,
|
subject: `Get Sygnal Password Recovery`,
|
||||||
html: `your new password is: <br/> <strong> ${passwords}</strong><br/><br/>If you have not requested this email then, please ignore it.`,
|
html: `your new password is: <br/> <strong> ${passwords}</strong><br/><br/>If you have not requested this email then, please ignore it.`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
28
server.js
28
server.js
@ -1,19 +1,18 @@
|
|||||||
|
import dotenv from "dotenv";
|
||||||
import dotenv from 'dotenv'
|
dotenv.config();
|
||||||
dotenv.config()
|
import app from "./app.js";
|
||||||
import app from "./app.js"
|
import connectDatabase from "./database/db.js";
|
||||||
import connectDatabase from "./database/db.js"
|
import cloudinary from "cloudinary";
|
||||||
import cloudinary from "cloudinary"
|
|
||||||
|
|
||||||
// Connecting to database
|
// Connecting to database
|
||||||
connectDatabase()
|
connectDatabase();
|
||||||
|
|
||||||
//console.log(process.env.CLOUDINARY_API_KEY)
|
//console.log(process.env.CLOUDINARY_API_KEY)
|
||||||
//cloudenary uses
|
//cloudenary uses
|
||||||
cloudinary.config({
|
cloudinary.config({
|
||||||
cloud_name: process.env.CLOUDINARY_NAME,
|
cloud_name: process.env.CLOUDINARY_NAME,
|
||||||
api_key: process.env.CLOUDINARY_API_KEY,
|
api_key: process.env.CLOUDINARY_API_KEY,
|
||||||
api_secret: process.env.CLOUDINARY_API_SECRET,
|
api_secret: process.env.CLOUDINARY_API_SECRET,
|
||||||
});
|
});
|
||||||
//<---------deployement------------->``
|
//<---------deployement------------->``
|
||||||
// const data_dir = path.resolve();
|
// const data_dir = path.resolve();
|
||||||
@ -26,14 +25,13 @@ cloudinary.config({
|
|||||||
// );
|
// );
|
||||||
// } else {
|
// } else {
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.send("API is running..");
|
res.send("API is running..");
|
||||||
});
|
});
|
||||||
// }
|
// }
|
||||||
//<---------deployement------------->
|
//<---------deployement------------->
|
||||||
const server = app.listen(process.env.PORT, () => {
|
const server = app.listen(process.env.PORT, () => {
|
||||||
console.log(`Server is working on http://localhost:${process.env.PORT}`)
|
console.log(`Server is working on http://localhost:${process.env.PORT}`);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
// Unhandled Promise Rejection
|
// Unhandled Promise Rejection
|
||||||
// process.on("unhandledRejection", (err) => {
|
// process.on("unhandledRejection", (err) => {
|
||||||
@ -43,4 +41,4 @@ const server = app.listen(process.env.PORT, () => {
|
|||||||
// server.close(() => {
|
// server.close(() => {
|
||||||
// process.exit(1);
|
// process.exit(1);
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
Loading…
Reference in New Issue
Block a user