first commit
30
app.js
@ -23,35 +23,5 @@ app.use(fileUpload({
|
||||
//auth
|
||||
import user from "./routes/userRoute.js"
|
||||
app.use("/api/v1/", user);
|
||||
//category
|
||||
import category from "./routes/categoryRoute.js"
|
||||
app.use("/api", category);
|
||||
//directory
|
||||
import directory from "./routes/directoryRoute.js"
|
||||
app.use("/api", directory);
|
||||
//News
|
||||
import news from "./routes/newsRoute.js"
|
||||
app.use("/api", news);
|
||||
//Events
|
||||
import Event from "./routes/EventsRoute.js"
|
||||
app.use("/api", Event);
|
||||
//Offers
|
||||
import Offer from "./routes/OffersRoute.js"
|
||||
app.use("/api", Offer);
|
||||
//banner
|
||||
import banner from "./routes/bannerRoute.js"
|
||||
app.use("/api", banner);
|
||||
//cmp-Ristriction
|
||||
import cmpRistriction from "./routes/cmp-restriction-Route.js"
|
||||
app.use("/api", cmpRistriction);
|
||||
//feedback
|
||||
import feedback from "./routes/feedbackRoute.js"
|
||||
app.use("/api", feedback);
|
||||
|
||||
//requirement
|
||||
import requirement from "./routes/RequirementRoute.js"
|
||||
app.use("/api", requirement);
|
||||
//requirement
|
||||
import faqs from "./routes/FaqsRoute.js"
|
||||
app.use("/api", faqs);
|
||||
export default app;
|
@ -1,269 +0,0 @@
|
||||
import Events from "../models/EventsModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
import { ResisterUserModel } from "../models/EventsModel.js"
|
||||
// import cloudinary from "../Utils/cloudinary.js"
|
||||
//import { v2 as cloudinary } from 'cloudinary'
|
||||
|
||||
export const createEvent = async (req, res) => {
|
||||
|
||||
try {
|
||||
// console.log(req.body)
|
||||
const files = req.files.image;
|
||||
|
||||
// console.log(files)
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
const { title, location, description, date, time } = req.body;
|
||||
|
||||
const data = await Events.create({
|
||||
title,
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
location,
|
||||
description,
|
||||
date,
|
||||
time,
|
||||
addedBy: req.user.id
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Event Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create Event !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Event
|
||||
export const getAllEvent = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Event = await Events.find();
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
Event,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Event
|
||||
export const getOneEvent = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Event = await Events.findById(req.params.id);
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
Event,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update Event
|
||||
export const updateEvent = async (req, res) => {
|
||||
try {
|
||||
const newEventData = {
|
||||
title: req.body.title,
|
||||
description: req.body.description,
|
||||
location: req.body.location,
|
||||
date: req.body.date,
|
||||
time: req.body.time,
|
||||
};
|
||||
|
||||
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
const getEvent = await Events.findById(req.params.id);
|
||||
|
||||
const imageId = getEvent.image.public_id;
|
||||
// console.log(imageId)
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
// await cloudinary.uploader.destroy(imageId, function (result) { console.log(result) });
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
// console.log(myCloud)
|
||||
newEventData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
// console.log(newCategoryData)
|
||||
//req.user.id,
|
||||
const ModifyEvent = await Events.findByIdAndUpdate(req.params.id, newEventData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyEvent
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate Event!!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one Event
|
||||
export const deleteEvent = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const getEvent = await Events.findById(req.params.id);
|
||||
// console.log(categ)
|
||||
const imageId = getEvent.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
|
||||
//-------------------------//
|
||||
const event = await Events.findByIdAndDelete(req.params.id)
|
||||
if (!event) {
|
||||
return res.status(404).json({ message: 'Event Not Found' });
|
||||
}
|
||||
await event.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Event Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete event !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//EventRegisterUser
|
||||
|
||||
export const RegisterUserInEvent = async (req, res) => {
|
||||
try {
|
||||
const totalUserRegister = await ResisterUserModel.findOne({
|
||||
userId: req.user.id,
|
||||
eventId: req.params.id,
|
||||
})
|
||||
if (totalUserRegister) {
|
||||
|
||||
return res.status(200).json({
|
||||
success: false,
|
||||
msg: "You Have Already Registered for this Event"
|
||||
});
|
||||
}
|
||||
const Event = await ResisterUserModel.create({
|
||||
eventId: req.params.id,
|
||||
userId: req.user.id,
|
||||
|
||||
})
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " Register Successfully!!",
|
||||
Event,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Register !!"
|
||||
});
|
||||
}
|
||||
}
|
||||
//getAllRegisterUser
|
||||
export const getAllRegisterUser = async (req, res) => {
|
||||
try {
|
||||
const totalUserRegister = await ResisterUserModel.find({ eventId: req.params.id }).count()
|
||||
const user = await ResisterUserModel.find({ eventId: req.params.id }).populate('userId')
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " get All user Register in Event Successfully!!",
|
||||
totalUserRegister,
|
||||
user,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
}
|
||||
//getSingleRegisterUser
|
||||
export const getSingleRegisterUser = async (req, res) => {
|
||||
try {
|
||||
|
||||
const user = await ResisterUserModel.findById(req.params.id).populate('userId').
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " get Successfully!!",
|
||||
user,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//share app (api)
|
||||
export const shareApp = async (req, res) => {
|
||||
|
||||
try {
|
||||
if (!process.env.APP_STORE_URL) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
msg: "App URl not Found"
|
||||
});
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
AppUrl: `${process.env.APP_STORE_URL}`,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -1,162 +0,0 @@
|
||||
import FaqsModel from "../models/FaqsModel.js";
|
||||
import cloudinary from "cloudinary";
|
||||
// import cloudinary from "../Utils/cloudinary.js"
|
||||
//import { v2 as cloudinary } from 'cloudinary'
|
||||
|
||||
export const createFaqs = async (req, res) => {
|
||||
|
||||
try {
|
||||
// const files = req.files.image;
|
||||
|
||||
// console.log(files.tempFilePath)
|
||||
// const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
// folder: "cmp/News",
|
||||
// },
|
||||
// function (error, result) { (result, error) });
|
||||
const { topic, description } = req.body;
|
||||
|
||||
const Faqs = await FaqsModel.create({
|
||||
topic,
|
||||
// image: {
|
||||
// public_id: myCloud.public_id,
|
||||
// url: myCloud.secure_url,
|
||||
// },
|
||||
description,
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Faqs Successfully!!",
|
||||
Faqs,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Faqs
|
||||
export const getAllFaqs = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Faqs = await FaqsModel.find();
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Faqs Successfully!!",
|
||||
Faqs,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One news
|
||||
export const getOneFaqs = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Faqs = await FaqsModel.findById(req.params.id);
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Faqs Successfully!!",
|
||||
Faqs,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update Faqs
|
||||
export const updateFaqs = async (req, res) => {
|
||||
try {
|
||||
const newFaqsData = {
|
||||
topic: req.body.topic,
|
||||
description: req.body.description,
|
||||
};
|
||||
//console.log(req.files)
|
||||
|
||||
// if (req.files) {
|
||||
// const files = req.files.image;
|
||||
|
||||
// const newsImage = await FaqsModel.findById(req.params.id);
|
||||
|
||||
// const imgId = newsImage.image.public_id;
|
||||
|
||||
// //delete image from claudinary
|
||||
// await cloudinary.uploader.destroy(imgId)
|
||||
// // await cloudinary.uploader.destroy(imageId, function (result) { console.log(result) });
|
||||
// const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
// folder: "cmp/image",
|
||||
// },
|
||||
// function (error, result) { (result, error) });
|
||||
// // console.log(myCloud)
|
||||
// newFaqsData.image = {
|
||||
// public_id: myCloud.public_id,
|
||||
// url: myCloud.secure_url,
|
||||
// };
|
||||
// }
|
||||
// console.log(newFaqsData)
|
||||
//req.user.id,
|
||||
const ModifyFaqs = await FaqsModel.findByIdAndUpdate(req.params.id, newFaqsData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyFaqs
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one Faqs
|
||||
export const deleteOneFaqs = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
// const findFaqs = await FaqsModel.findById(req.params.id);
|
||||
// // console.log(newsImageId)
|
||||
// const imgId = findFaqs.image.public_id;
|
||||
// await cloudinary.uploader.destroy(imgId)
|
||||
|
||||
//-------------------------//
|
||||
const Faqs = await FaqsModel.findByIdAndDelete(req.params.id)
|
||||
if (!Faqs) {
|
||||
return res.status(400).json({ message: 'Faqs Not Found' });
|
||||
}
|
||||
await Faqs.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Faqs Deleted Successfully!!",
|
||||
// Faqs,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -1,162 +0,0 @@
|
||||
import News from "../models/newsModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
// import cloudinary from "../Utils/cloudinary.js"
|
||||
//import { v2 as cloudinary } from 'cloudinary'
|
||||
|
||||
export const createNews = async (req, res) => {
|
||||
|
||||
try {
|
||||
const files = req.files.image;
|
||||
|
||||
// console.log(files.tempFilePath)
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/News",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
const { title, description } = req.body;
|
||||
|
||||
const news = await News.create({
|
||||
title,
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
description,
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create News Successfully!!",
|
||||
news,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All news
|
||||
export const getAllNews = async (req, res) => {
|
||||
|
||||
try {
|
||||
const news = await News.find();
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
news,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One news
|
||||
export const getOneNews = async (req, res) => {
|
||||
|
||||
try {
|
||||
const news = await News.findById(req.params.id);
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
news,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update news
|
||||
export const updateNews = async (req, res) => {
|
||||
try {
|
||||
const newNewsData = {
|
||||
title: req.body.title,
|
||||
description: req.body.description,
|
||||
};
|
||||
//console.log(req.files)
|
||||
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
|
||||
const newsImage = await News.findById(req.params.id);
|
||||
|
||||
const imgId = newsImage.image.public_id;
|
||||
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(imgId)
|
||||
// await cloudinary.uploader.destroy(imageId, function (result) { console.log(result) });
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
// console.log(myCloud)
|
||||
newNewsData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
console.log(newNewsData)
|
||||
//req.user.id,
|
||||
const ModifyNews = await News.findByIdAndUpdate(req.params.id, newNewsData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyNews
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one news
|
||||
export const deleteOneNews = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const findNews = await News.findById(req.params.id);
|
||||
// console.log(newsImageId)
|
||||
const imgId = findNews.image.public_id;
|
||||
await cloudinary.uploader.destroy(imgId)
|
||||
|
||||
//-------------------------//
|
||||
const news = await News.findByIdAndDelete(req.params.id)
|
||||
if (!news) {
|
||||
return res.status(400).json({ message: 'News Not Found' });
|
||||
}
|
||||
await news.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "News Deleted Successfully!!",
|
||||
// news,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -1,157 +0,0 @@
|
||||
import Offers from "../models/OffersModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
|
||||
export const createOffer = async (req, res) => {
|
||||
|
||||
try {
|
||||
//console.log(req.body)
|
||||
const files = req.files.image;
|
||||
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
const { title, location, description, bisunessName } = req.body;
|
||||
|
||||
const data = await Offers.create({
|
||||
title,
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
location,
|
||||
description,
|
||||
bisunessName
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Offer Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create Offer !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Product
|
||||
export const getAllOffer = async (req, res) => {
|
||||
|
||||
try {
|
||||
const offer = await Offers.find();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch All Offer Successfully!!",
|
||||
offer,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Product
|
||||
export const getOneOffer = async (req, res) => {
|
||||
|
||||
try {
|
||||
const offer = await Offers.findById(req.params.id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
offer,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update offer
|
||||
export const updateOffer = async (req, res) => {
|
||||
try {
|
||||
const newOfferData = {
|
||||
title: req.body.title,
|
||||
description: req.body.description,
|
||||
location: req.body.location,
|
||||
bisunessName: req.body.bisunessName
|
||||
};
|
||||
|
||||
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
const getOffer = await Offers.findById(req.params.id);
|
||||
|
||||
const imageId = getOffer.image.public_id;
|
||||
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
newOfferData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
|
||||
//req.user.id,
|
||||
const ModifyOffer = await Offers.findByIdAndUpdate(req.params.id, newOfferData,
|
||||
|
||||
{ new: true }
|
||||
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyOffer
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate Offer!!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one category
|
||||
export const deleteOffer = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const getOffer = await Offers.findById(req.params.id);
|
||||
// console.log(categ)
|
||||
const imageId = getOffer.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
|
||||
//-------------------------//
|
||||
const offer = await Offers.findByIdAndDelete(req.params.id)
|
||||
if (!offer) {
|
||||
return res.status(400).json({ message: 'Offer Not Found' });
|
||||
}
|
||||
await offer.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Offer Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete Offer !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -1,305 +0,0 @@
|
||||
import RequirementModel from "../models/RequirementModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
import { RequirementCommentModel } from "../models/RequirementModel.js";
|
||||
// import cloudinary from "../Utils/cloudinary.js"
|
||||
//import { v2 as cloudinary } from 'cloudinary'
|
||||
|
||||
export const createRequirement = async (req, res) => {
|
||||
|
||||
try {
|
||||
let images = [];
|
||||
let Allfiles = req.files.image;
|
||||
// console.log(typeof Allfiles.tempFilePath)
|
||||
if (typeof Allfiles.tempFilePath === "string") {
|
||||
let filepath = Allfiles.tempFilePath;
|
||||
|
||||
images.push(filepath)
|
||||
} else {
|
||||
Allfiles.map(item => {
|
||||
images.push(item.tempFilePath);
|
||||
})
|
||||
}
|
||||
|
||||
const imagesLinks = [];
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
const result = await cloudinary.v2.uploader.upload(images[i], {
|
||||
folder: "cmp",
|
||||
});
|
||||
|
||||
imagesLinks.push({
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
req.body.image = imagesLinks;
|
||||
req.body.addedBy = req.user.id;
|
||||
|
||||
|
||||
// if (req.user.role === "admin"){
|
||||
// req.body.approved=true
|
||||
// }
|
||||
// else{
|
||||
// req.body.approved = false
|
||||
// }
|
||||
req.body.approved = (req.user.role === "admin" ? true : false);
|
||||
|
||||
|
||||
const Requirement = await RequirementModel.create(req.body);
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Requirement Successfully!!",
|
||||
Requirement,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Requirement
|
||||
export const getAllRequirement = async (req, res) => {
|
||||
|
||||
try {
|
||||
if (req.user.role === "admin") {
|
||||
const Requirement = await RequirementModel.find();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
Requirement,
|
||||
});
|
||||
}
|
||||
else {
|
||||
const Requirement = await RequirementModel.find({ approved: true });
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
Requirement,
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Requirement
|
||||
export const getOneRequirement = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Requirement = await RequirementModel.findById(req.params.id);
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
Requirement,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update Requirement
|
||||
export const updateRequirement = async (req, res) => {
|
||||
try {
|
||||
const Requirement = await RequirementModel.findById(req.params.id);
|
||||
if (!Requirement) {
|
||||
return res.status(400).json({ message: 'Requirement Not Found' });
|
||||
}
|
||||
//handle image------------------------------------------------------------
|
||||
let images = [];
|
||||
let Allfiles = req.files.image;
|
||||
// console.log(typeof Allfiles.tempFilePath)
|
||||
if (typeof Allfiles.tempFilePath === "string") {
|
||||
let filepath = Allfiles.tempFilePath;
|
||||
// console.log(filepath)
|
||||
images.push(filepath)
|
||||
} else {
|
||||
Allfiles.map(item => {
|
||||
images.push(item.tempFilePath);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if (images !== undefined) {
|
||||
// Deleting Images From Cloudinary
|
||||
for (let i = 0; i < Requirement.image.length; i++) {
|
||||
await cloudinary.v2.uploader.destroy(Requirement.image[i].public_id);
|
||||
}
|
||||
|
||||
const imagesLinks = [];
|
||||
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
const result = await cloudinary.v2.uploader.upload(images[i], {
|
||||
folder: "cmp",
|
||||
});
|
||||
|
||||
imagesLinks.push({
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
});
|
||||
}
|
||||
|
||||
req.body.image = imagesLinks;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
const ModifyRequirement = await RequirementModel.findByIdAndUpdate(req.params.id, req.body,
|
||||
|
||||
{
|
||||
new: true,
|
||||
runValidators: true,
|
||||
useFindAndModify: false
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyRequirement
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one Requirement
|
||||
export const deleteOneRequirement = async (req, res) => {
|
||||
|
||||
try {
|
||||
const findRequirement = await RequirementModel.findById(req.params.id);
|
||||
|
||||
if (!findRequirement) {
|
||||
return res.status(400).json({ message: 'Requirement Not Found' });
|
||||
}
|
||||
// Deleting Images From Cloudinary
|
||||
for (let i = 0; i < findRequirement.image.length; i++) {
|
||||
await cloudinary.v2.uploader.destroy(findRequirement.image[i].public_id);
|
||||
}
|
||||
|
||||
|
||||
await findRequirement.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Requirement Deleted Successfully!!",
|
||||
// news,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
//Approved(admin)
|
||||
export const Approved = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Requirement = await RequirementModel.findById(req.params.id);
|
||||
if (Requirement.approved === false) {
|
||||
Requirement.approved = true
|
||||
Requirement.save()
|
||||
} else {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: " already Approved",
|
||||
});
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " Approved Successfully!!",
|
||||
Requirement,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Approved !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//comment
|
||||
|
||||
export const AddComment = async (req, res) => {
|
||||
try {
|
||||
|
||||
const comment = await RequirementCommentModel.create({
|
||||
requirementId: req.params.id,
|
||||
userId: req.user._id,
|
||||
comment: req.body.comment
|
||||
|
||||
})
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " Create Successfully!!",
|
||||
comment,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
}
|
||||
//get All Comment
|
||||
export const getAllComment = async (req, res) => {
|
||||
try {
|
||||
|
||||
const comment = await RequirementCommentModel.find().populate('userId')
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " get All Comment Successfully!!",
|
||||
comment,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
}
|
||||
//get Comment
|
||||
export const getSingleComment = async (req, res) => {
|
||||
try {
|
||||
|
||||
const comment = await RequirementCommentModel.findById(req.params.id).populate('userId').
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " get Comment Successfully!!",
|
||||
comment,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
import Banners from "../models/bannerModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
// import cloudinary from "../Utils/cloudinary.js"
|
||||
//import { v2 as cloudinary } from 'cloudinary'
|
||||
|
||||
export const createBanner = async (req, res) => {
|
||||
|
||||
try {
|
||||
const files = req.files.image;
|
||||
// console.log(files)
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
|
||||
const { title, startDate, endDate } = req.body;
|
||||
const data = await Banners.create({
|
||||
title,
|
||||
// subTitle,
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
// section,
|
||||
startDate,
|
||||
endDate,
|
||||
// subSection
|
||||
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Banner Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create Banner !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Banners
|
||||
export const getAllBanner = async (req, res) => {
|
||||
|
||||
try {
|
||||
const banner = await Banners.find();
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
banner,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Banner
|
||||
export const getOneBanner = async (req, res) => {
|
||||
|
||||
try {
|
||||
const banner = await Banners.findById(req.params.id);
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
banner,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update Event
|
||||
export const updateBanner = async (req, res) => {
|
||||
try {
|
||||
|
||||
const newBannerData = {
|
||||
title: req.body.title,
|
||||
// subTitle: req.body.subTitle,
|
||||
|
||||
// section: req.body.section,
|
||||
// subSection: req.body.subSection,
|
||||
startDate: req.body.startDate,
|
||||
endDate: req.body.endDate,
|
||||
};
|
||||
|
||||
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
const getBanner = await Banners.findById(req.params.id);
|
||||
|
||||
const imageId = getBanner.image.public_id;
|
||||
// console.log(imageId)
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
// await cloudinary.uploader.destroy(imageId, function (result) { console.log(result) });
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
// console.log(myCloud)
|
||||
newBannerData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
|
||||
//req.user.id,
|
||||
const ModifyBanner = await Banners.findByIdAndUpdate(req.params.id, newBannerData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyBanner
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate Banner!!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one Banner
|
||||
export const deleteBanner = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const getBanner = await Banners.findById(req.params.id);
|
||||
// console.log(categ)
|
||||
const imageId = getBanner.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
|
||||
//-------------------------//
|
||||
const banner = await Banners.findByIdAndDelete(req.params.id)
|
||||
if (!banner) {
|
||||
return res.status(400).json({ message: 'banner Not Found' });
|
||||
}
|
||||
await banner.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "banner Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete banner !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -1,193 +0,0 @@
|
||||
import Category from "../models/categoryModel.js"
|
||||
import cloudinary from "cloudinary";
|
||||
|
||||
|
||||
export const createCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const files = req.files;
|
||||
|
||||
// ctegory upload
|
||||
const myCloud = await cloudinary.uploader.upload(files.image.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
|
||||
// ctegory(banner)upload
|
||||
const CategoryBanner = await cloudinary.uploader.upload(files.category_banner.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
const { name } = req.body;
|
||||
|
||||
const data = await Category.create({
|
||||
name,
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
category_banner: {
|
||||
public_id: CategoryBanner.public_id,
|
||||
url: CategoryBanner.secure_url,
|
||||
},
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Category Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Product
|
||||
export const getAllCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const category = await Category.find().sort({ createdAt: -1 });
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Product
|
||||
export const getOneCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const category = await Category.findById(req.params.id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
category,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update Category
|
||||
export const updateCategory = async (req, res) => {
|
||||
try {
|
||||
const newCategoryData = {
|
||||
name: req.body.name,
|
||||
};
|
||||
|
||||
|
||||
if (req.files) {
|
||||
|
||||
const categ = await Category.findById(req.params.id);
|
||||
if (req.files.image) {
|
||||
const imageId = categ.image.public_id;
|
||||
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
const files = req.files.image;
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
newCategoryData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
if (req.files.category_banner) {
|
||||
|
||||
const BannerImageId = categ.category_banner.public_id;
|
||||
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(BannerImageId)
|
||||
|
||||
|
||||
const files = req.files.category_banner;
|
||||
const BannerImage = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
newCategoryData.category_banner = {
|
||||
public_id: BannerImage.public_id,
|
||||
url: BannerImage.secure_url,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ModifyCategory = await Category.findByIdAndUpdate(req.params.id, newCategoryData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyCategory
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete one category
|
||||
export const deleteOneCategory = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const categ = await Category.findById(req.params.id);
|
||||
if (categ.category_banner.public_id) {
|
||||
const bannerImageId = categ.category_banner.public_id;
|
||||
await cloudinary.uploader.destroy(bannerImageId)
|
||||
|
||||
}
|
||||
|
||||
// console.log(categ)
|
||||
const imageId = categ.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
|
||||
//-------------------------//
|
||||
const category = await Category.findByIdAndDelete(req.params.id)
|
||||
if (!category) {
|
||||
return res.status(400).json({ message: 'category Not Found' });
|
||||
}
|
||||
await category.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "category Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
@ -1,166 +0,0 @@
|
||||
import cmpRestrictionModel from "../models/cmp-restriction-model.js"
|
||||
import cloudinary from "cloudinary";
|
||||
export const createRestriction = async (req, res) => {
|
||||
|
||||
try {
|
||||
|
||||
const CMSData = {
|
||||
title: req.body.title,
|
||||
page_data: req.body.page_data,
|
||||
};
|
||||
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
CMSData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.url,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const data = await cmpRestrictionModel.create(
|
||||
CMSData
|
||||
);
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Restriction Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create Restriction !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All
|
||||
export const getAllRestriction = async (req, res) => {
|
||||
|
||||
try {
|
||||
const CmpRestriction = await cmpRestrictionModel.find();
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
CmpRestriction,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//get One
|
||||
export const getOneRestriction = async (req, res) => {
|
||||
|
||||
try {
|
||||
const CmpRestriction = await cmpRestrictionModel.findById(req.params.id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Restriction Successfully!!",
|
||||
CmpRestriction,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update
|
||||
export const updateRestriction = async (req, res) => {
|
||||
try {
|
||||
if (!req.params.id) {
|
||||
return res.status(404).json({
|
||||
msg: "CMS Id Not Found!"
|
||||
});
|
||||
}
|
||||
const CMSData = {
|
||||
title: req.body.title,
|
||||
page_data: req.body.page_data,
|
||||
};
|
||||
if (req.files) {
|
||||
const getCms = await cmpRestrictionModel.findById(req.params.id);
|
||||
//delete from cloudinary
|
||||
if (getCms.image.public_id) {
|
||||
const imageId = getCms.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
}
|
||||
const files = req.files.image;
|
||||
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
CMSData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.url,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const ModifyCms = await cmpRestrictionModel.findByIdAndUpdate(req.params.id, CMSData,
|
||||
{ new: true }
|
||||
);
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyCms
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//delete
|
||||
export const deleteCms = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
const getCms = await cmpRestrictionModel.findById(req.params.id);
|
||||
|
||||
if (getCms.image.public_id) {
|
||||
const imageId = getCms.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
}
|
||||
|
||||
//-------------------------//
|
||||
const Cms = await cmpRestrictionModel.findByIdAndDelete(req.params.id)
|
||||
if (!Cms) {
|
||||
return res.status(400).json({ message: 'CMS Not Found' });
|
||||
}
|
||||
await Cms.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "CMS Deleted Successfully!!",
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,248 +0,0 @@
|
||||
import directoryModel from "../models/directoryModel.js";
|
||||
import cloudinary from "cloudinary";
|
||||
export const createDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
let images;
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
images = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
}
|
||||
}
|
||||
const {
|
||||
name,
|
||||
phone,
|
||||
email,
|
||||
Bname,
|
||||
Sname,
|
||||
country,
|
||||
city,
|
||||
description,
|
||||
category,
|
||||
status,
|
||||
Glocation,
|
||||
LinkedinUrl,
|
||||
FacebookUrl,
|
||||
InstagramUrl,
|
||||
} = req.body;
|
||||
const data = await directoryModel.create({
|
||||
|
||||
name,
|
||||
phone,
|
||||
email,
|
||||
Building_Name: Bname,
|
||||
Street_Name: Sname,
|
||||
country,
|
||||
city,
|
||||
description,
|
||||
category,
|
||||
status,
|
||||
Glocation,
|
||||
LinkedinUrl,
|
||||
FacebookUrl,
|
||||
InstagramUrl,
|
||||
image: images,
|
||||
userId: req.user.id
|
||||
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Directory Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All Directory(User)
|
||||
export const getAllDirectoryUser = async (req, res) => {
|
||||
|
||||
try {
|
||||
const directory = await directoryModel.find({ status: true });
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
directory,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//get All Directory(admin)
|
||||
export const getAllDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
|
||||
const directory = await directoryModel.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
directory,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get One Directory
|
||||
export const getOneDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const directory = await directoryModel.findById(req.params.id);
|
||||
// console.log(directory.status)
|
||||
// console.log(category)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
directory,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const updateDirectory = async (req, res) => {
|
||||
try {
|
||||
let images;
|
||||
if (req.files) {
|
||||
const files = req.files.image;
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
images = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
}
|
||||
}
|
||||
req.body.image = images;
|
||||
const ModifyDirectory = await directoryModel.findByIdAndUpdate(req.params.id, req.body,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyDirectory
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate !!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//delete one category
|
||||
export const deleteOneDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary(if image exist)
|
||||
const dir = await directoryModel.findById(req.params.id);
|
||||
// console.log(categ)
|
||||
if (dir.image.public_id) {
|
||||
const imageId = dir.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
}
|
||||
|
||||
const directory = await directoryModel.findByIdAndDelete(req.params.id)
|
||||
if (!directory) {
|
||||
return res.status(400).json({ message: 'Directory Not Found' });
|
||||
}
|
||||
await directory.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Directory Deleted Successfully!!",
|
||||
// category,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to Delete !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//get One Directory from userid
|
||||
export const getSelfDirectory = async (req, res) => {
|
||||
|
||||
try {
|
||||
const directory = await directoryModel.find({ userId: req.user.id });
|
||||
|
||||
if (!directory) {
|
||||
return res.status(400).json({ message: 'No self directory exist ' });
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
directory,
|
||||
});
|
||||
} catch (error) {
|
||||
//console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
export const setStatus = async (req, res) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
if (!id) return res.status(400).json({ message: 'id is required' });
|
||||
// console.log(id)
|
||||
const directory = await directoryModel.findById(req.params.id)
|
||||
|
||||
if (!directory)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: 'Did not find directory by given id' });
|
||||
if (directory.status === "true") {
|
||||
directory.status = false
|
||||
}
|
||||
else {
|
||||
directory.status = true
|
||||
}
|
||||
|
||||
directory.save();
|
||||
// console.log(directory)
|
||||
res.status(200).json(directory);
|
||||
} catch (error) {
|
||||
// console.log(error);
|
||||
res.status(500).json({
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
@ -1,63 +0,0 @@
|
||||
import feedbackModel from "../models/feedbackModel.js"
|
||||
|
||||
export const createFeedback = async (req, res) => {
|
||||
try {
|
||||
const { name, description } = req.body;
|
||||
// req.body.user = req.user.id;
|
||||
const feedback = await feedbackModel.create({
|
||||
name,
|
||||
description,
|
||||
user: req.user._id
|
||||
});
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create feedback Successfully!!",
|
||||
feedback,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All feedback
|
||||
export const getAllFeedback = async (req, res) => {
|
||||
|
||||
try {
|
||||
const feedback = await feedbackModel.find();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch feedback Successfully!!",
|
||||
feedback
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All feedback
|
||||
export const getAOneFeedback = async (req, res) => {
|
||||
|
||||
try {
|
||||
const feedback = await feedbackModel.findById(req.params.id);
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch feedback Successfully!!",
|
||||
feedback
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -6,18 +6,24 @@ import sendToken from "../Utils/jwtToken.js"
|
||||
import sendEmail from "../Utils/sendEmail.js"
|
||||
import crypto from "crypto"
|
||||
import cloudinary from "cloudinary"
|
||||
import generator from 'generate-password'
|
||||
import password from 'secure-random-password'
|
||||
// 1.Register a User
|
||||
export const registerUser = async (req, res, next) => {
|
||||
try {
|
||||
const { name, email, password, phone } = req.body;
|
||||
let findUser = await User.findOne({ email })
|
||||
if (findUser) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ success: false, message: "User already exists" });
|
||||
}
|
||||
const files = req.files.avatar;
|
||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||
folder: "cmp-user/image",
|
||||
},
|
||||
function (error, result) { (result, error) });
|
||||
|
||||
const { name, email, password, phone } = req.body;
|
||||
|
||||
|
||||
const user = await User.create({
|
||||
name,
|
||||
@ -32,14 +38,9 @@ export const registerUser = async (req, res, next) => {
|
||||
sendToken(user, 201, res);
|
||||
} catch (e) {
|
||||
// console.log(e.message);
|
||||
if (e.toString().includes('E11000 duplicate key error collection')) {
|
||||
return res.status(400).json({
|
||||
status: 'User Already Exists'
|
||||
});
|
||||
}
|
||||
return res
|
||||
.status(400)
|
||||
.json({ status: 'Error Communicating with server' });
|
||||
.json({ success: false, message: e.message });
|
||||
}
|
||||
|
||||
};
|
||||
@ -66,11 +67,7 @@ export const loginUser = catchAsyncErrors(async (req, res, next) => {
|
||||
if (!isPasswordMatched) {
|
||||
return res.status(400).json({ message: 'Invalid Email or Password' });
|
||||
}
|
||||
// const token = user.getJWTToken();
|
||||
// res.status(201).json({
|
||||
// success: true,
|
||||
// token,
|
||||
// })
|
||||
|
||||
sendToken(user, 200, res);
|
||||
});
|
||||
|
||||
@ -130,7 +127,7 @@ export const forgotPassword = catchAsyncErrors(async (req, res, next) => {
|
||||
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
|
||||
subject: `CMP Password Recovery`,
|
||||
subject: `ATP Password Recovery`,
|
||||
html: `your new password is: <br/> <strong> ${passwords}</strong><br/><br/>If you have not requested this email then, please ignore it.`
|
||||
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ export const isAuthenticatedUser = async (req, res, next) => {
|
||||
|
||||
const frontdecoded = jwt.verify(fronttoken, process.env.JWT_SECRET);
|
||||
if (!frontdecoded) {
|
||||
return res.status(200).json({
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "incorrect token",
|
||||
});
|
||||
|
@ -1,67 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const eventSchema = new mongoose.Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
location: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
addedOn: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const eventModel = mongoose.model("event", eventSchema);
|
||||
export default eventModel
|
||||
|
||||
const ResisterUserSchema = new mongoose.Schema(
|
||||
{
|
||||
|
||||
eventId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const ResisterUserModel = mongoose.model("RegisterUserInEvent", ResisterUserSchema);
|
||||
export { ResisterUserModel }
|
@ -1,26 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const faqsSchema = new mongoose.Schema(
|
||||
{
|
||||
topic: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
// image:
|
||||
// {
|
||||
// public_id: {
|
||||
// type: String,
|
||||
// required: true,
|
||||
// },
|
||||
// url: {
|
||||
// type: String,
|
||||
// required: true,
|
||||
// },
|
||||
// },
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const FaqsModel = mongoose.model("Faqs", faqsSchema);
|
||||
export default FaqsModel;
|
@ -1,39 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const offerSchema = new mongoose.Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
bisunessName: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
location: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
addedOn: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const offerModel = mongoose.model("offer", offerSchema);
|
||||
export default offerModel
|
@ -1,70 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const RequirementSchema = new mongoose.Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
areaOfInterest: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
|
||||
image: [
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
approved: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const RequirementModel = mongoose.model("Requirement", RequirementSchema);
|
||||
export default RequirementModel;
|
||||
|
||||
|
||||
const RequirementCommentSchema = new mongoose.Schema(
|
||||
{
|
||||
|
||||
requirementId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
|
||||
comment: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
|
||||
userId: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const RequirementCommentModel = mongoose.model("RequirementComment", RequirementCommentSchema);
|
||||
export { RequirementCommentModel };
|
@ -1,47 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const bannerSchema = new mongoose.Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
// subTitle: {
|
||||
// type: String,
|
||||
// required: true
|
||||
// },
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
// section: {
|
||||
// type: String,
|
||||
|
||||
// },
|
||||
// subSection: {
|
||||
// type: String,
|
||||
// },
|
||||
|
||||
startDate: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
endDate: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
addedOn: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const bannerModel = mongoose.model("banner", bannerSchema);
|
||||
export default bannerModel
|
@ -1,38 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const categorySchema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
category_banner:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
// required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
// required: true,
|
||||
},
|
||||
},
|
||||
addedOn: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const categoryUpload = mongoose.model("category", categorySchema);
|
||||
export default categoryUpload;
|
@ -1,29 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const cmpRisSchema = new mongoose.Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
page_data: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const cmpRisModel = mongoose.model("cmp-res", cmpRisSchema);
|
||||
export default cmpRisModel;
|
@ -1,79 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const directorySchema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
phone: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
// required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
// required: true,
|
||||
},
|
||||
},
|
||||
Building_Name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
Street_Name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
country: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
city: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
category: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
Glocation: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
LinkedinUrl: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
FacebookUrl: {
|
||||
type: String,
|
||||
},
|
||||
InstagramUrl: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
userId: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
// required: true,
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const directoryModel = mongoose.model("directory", directorySchema);
|
||||
export default directoryModel;
|
@ -1,20 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const feedbackSchema = new mongoose.Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
user: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const feedbackModel = mongoose.model("feedback", feedbackSchema);
|
||||
export default feedbackModel
|
@ -1,31 +0,0 @@
|
||||
import mongoose from "mongoose"
|
||||
const newsSchema = new mongoose.Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
image:
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
addedOn: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const newsUpload = mongoose.model("news", newsSchema);
|
||||
export default newsUpload;
|
@ -21,7 +21,7 @@ const userSchema = new mongoose.Schema({
|
||||
},
|
||||
phone: {
|
||||
type: Number,
|
||||
required: [true, "Please Enter Your phone no."],
|
||||
// required: [true, "Please Enter Your phone no."],
|
||||
maxLength: [12, "phone cannot exceed 12 characters"],
|
||||
minLength: [6, "phone should have more than 6 characters"],
|
||||
},
|
||||
|
4
package-lock.json
generated
@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "dashboard-backend",
|
||||
"name": "atp-backend",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "dashboard-backend",
|
||||
"name": "atp-backend",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "dashboard-backend",
|
||||
"name": "atp-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
|
@ -1,27 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createEvent,
|
||||
getAllEvent,
|
||||
updateEvent,
|
||||
deleteEvent,
|
||||
getOneEvent,
|
||||
RegisterUserInEvent,
|
||||
getAllRegisterUser,
|
||||
getSingleRegisterUser,
|
||||
shareApp
|
||||
|
||||
} from "../controllers/EventsController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
router.route("/event/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createEvent)
|
||||
router.route("/event/getAll/").get(getAllEvent)
|
||||
router.route("/event/getOne/:id").get(getOneEvent)
|
||||
router.route("/event/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateEvent);
|
||||
router.route("/event/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteEvent);
|
||||
//share app
|
||||
router.route("/app/share/").get(shareApp)
|
||||
//user
|
||||
router.route("/event/user/register/:id").post(isAuthenticatedUser, RegisterUserInEvent)
|
||||
router.route("/event/admin/registerUser/getAll/:id").get(isAuthenticatedUser, getAllRegisterUser)
|
||||
router.route("/event/getOne/registerUser/:id").get(isAuthenticatedUser, getSingleRegisterUser)
|
||||
export default router;
|
@ -1,16 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createFaqs,
|
||||
getAllFaqs,
|
||||
getOneFaqs,
|
||||
updateFaqs,
|
||||
deleteOneFaqs
|
||||
} from "../controllers/FaqsController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
router.route("/faqs/create/").post(isAuthenticatedUser, createFaqs)
|
||||
router.route("/faqs/getAll/").get(isAuthenticatedUser, getAllFaqs)
|
||||
router.route("/faqs/getOne/:id").get(isAuthenticatedUser, getOneFaqs)
|
||||
router.route("/faqs/update/:id").put(isAuthenticatedUser, updateFaqs);
|
||||
router.route("/faqs/delete/:id").delete(isAuthenticatedUser, deleteOneFaqs);
|
||||
export default router;
|
@ -1,17 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createOffer,
|
||||
getAllOffer,
|
||||
updateOffer,
|
||||
deleteOffer,
|
||||
getOneOffer
|
||||
} from "../controllers/OffersController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
|
||||
router.route("/offer/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createOffer)//isAuthenticatedUser, authorizeRoles("admin"),
|
||||
router.route("/offer/getAll/").get(getAllOffer)
|
||||
router.route("/offer/getOne/:id").get(getOneOffer)
|
||||
router.route("/offer/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateOffer);//isAuthenticatedUser, authorizeRoles("admin"),
|
||||
router.route("/offer/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOffer);//isAuthenticatedUser, authorizeRoles("admin"),
|
||||
export default router;
|
@ -1,28 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createRequirement,
|
||||
getAllRequirement,
|
||||
getOneRequirement,
|
||||
updateRequirement,
|
||||
deleteOneRequirement,
|
||||
Approved,
|
||||
AddComment,
|
||||
getAllComment,
|
||||
getSingleComment
|
||||
} from "../controllers/RequirementController.js"
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/requirement/create/").post(isAuthenticatedUser, createRequirement)
|
||||
router.route("/requirement/getAll/").get(isAuthenticatedUser, getAllRequirement)
|
||||
router.route("/requirement/getOne/:id").get(isAuthenticatedUser, getOneRequirement)
|
||||
router.route("/requirement/update/:id").put(isAuthenticatedUser, updateRequirement);
|
||||
router.route("/requirement/delete/:id").delete(isAuthenticatedUser, deleteOneRequirement);
|
||||
//user
|
||||
router.route("/requirement/comment/create/:id").post(isAuthenticatedUser, AddComment);
|
||||
|
||||
//admin
|
||||
router.route("/admin/requirement/approve/:id").get(isAuthenticatedUser, authorizeRoles("admin"), Approved);
|
||||
router.route("/admin/requirement/comment/getOne/:id").get(isAuthenticatedUser, getSingleComment);
|
||||
router.route("/admin/requirement/comment/getAll").get(isAuthenticatedUser, getAllComment);
|
||||
export default router;
|
@ -1,16 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createBanner,
|
||||
getAllBanner,
|
||||
updateBanner,
|
||||
deleteBanner,
|
||||
getOneBanner
|
||||
} from "../controllers/bannerController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
router.route("/banner/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createBanner)
|
||||
router.route("/banner/getAll/").get(getAllBanner)
|
||||
router.route("/banner/getOne/:id").get(getOneBanner)
|
||||
router.route("/banner/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateBanner);
|
||||
router.route("/banner/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteBanner);
|
||||
export default router;
|
@ -1,17 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createCategory,
|
||||
getAllCategory,
|
||||
updateCategory,
|
||||
deleteOneCategory,
|
||||
getOneCategory
|
||||
} from "../controllers/categoryController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
|
||||
router.route("/category/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createCategory)
|
||||
router.route("/category/getAll/").get(getAllCategory)
|
||||
router.route("/category/getOne/:id").get(getOneCategory)
|
||||
router.route("/category/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateCategory);
|
||||
router.route("/category/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOneCategory);
|
||||
export default router;
|
@ -1,21 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createRestriction,
|
||||
getAllRestriction,
|
||||
updateRestriction,
|
||||
getOneRestriction,
|
||||
deleteCms
|
||||
} from "../controllers/cmp-restriction-Controller.js"
|
||||
const router = express.Router();
|
||||
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
router.route("/restriction/cms/create/").post(isAuthenticatedUser, authorizeRoles('admin'), createRestriction)
|
||||
|
||||
router.route("/restriction/getAll").get(getAllRestriction)
|
||||
router.route("/restriction/getOne/:id").get(getOneRestriction)
|
||||
router.route("/restriction/cms/update/:id").put(isAuthenticatedUser, authorizeRoles('admin'), updateRestriction);
|
||||
router.route("/restriction/cms/delete/:id").delete(isAuthenticatedUser, authorizeRoles('admin'), deleteCms);
|
||||
|
||||
|
||||
export default router;
|
||||
getAllRestriction
|
@ -1,42 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createDirectory,
|
||||
getAllDirectory,
|
||||
updateDirectory,
|
||||
deleteOneDirectory,
|
||||
getOneDirectory,
|
||||
getSelfDirectory,
|
||||
setStatus,
|
||||
getAllDirectoryUser
|
||||
|
||||
} from "../controllers/directoryController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
|
||||
|
||||
import multer from 'multer'
|
||||
|
||||
const uploaderImage = multer({
|
||||
storage: multer.diskStorage({}),
|
||||
fileFilter: (req, file, cb) => {
|
||||
let ext = path.extname(file.originalname);
|
||||
if (ext !== ".jpg" && ext !== ".jpeg" && ext !== ".png") {
|
||||
cb(new Error("File type not supported!"), false)
|
||||
return
|
||||
}
|
||||
cb(null, true);
|
||||
}
|
||||
});
|
||||
router.route("/directory/create/").post(isAuthenticatedUser, createDirectory)
|
||||
|
||||
router.route("/directory/user/getAll/").get(getAllDirectoryUser)
|
||||
router.route("/directory/getAll/").get(isAuthenticatedUser, authorizeRoles('admin'), getAllDirectory)
|
||||
router.route("/directory/getOne/:id").get(getOneDirectory)
|
||||
router.route("/directory/update/:id").put(isAuthenticatedUser, updateDirectory);
|
||||
router.route("/directory/delete/:id").delete(isAuthenticatedUser, deleteOneDirectory);
|
||||
//get Directory from user id
|
||||
router.route("/directory/self/").get(isAuthenticatedUser, getSelfDirectory);
|
||||
router.route("/directory/admin/setStatus/:id").get(isAuthenticatedUser, authorizeRoles('admin'), setStatus);
|
||||
|
||||
|
||||
export default router;
|
@ -1,13 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createFeedback,
|
||||
getAllFeedback,
|
||||
getAOneFeedback
|
||||
|
||||
} from "../controllers/feedbackController.js"
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
router.route("/feedback/create/").post(isAuthenticatedUser, createFeedback)
|
||||
router.route("/feedback/getAll/").get(isAuthenticatedUser, authorizeRoles('admin'), getAllFeedback)
|
||||
router.route("/feedback/getOne/:id").get(isAuthenticatedUser, authorizeRoles('admin'), getAOneFeedback)
|
||||
export default router;
|
@ -1,17 +0,0 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createNews,
|
||||
getAllNews,
|
||||
getOneNews,
|
||||
updateNews,
|
||||
deleteOneNews
|
||||
} from "../controllers/NewsController.js"
|
||||
import { authorizeRoles, isAuthenticatedUser } from "../middlewares/auth.js";
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/news/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createNews)
|
||||
router.route("/news/getAll/").get(getAllNews)
|
||||
router.route("/news/getOne/:id").get(getOneNews)
|
||||
router.route("/news/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateNews);
|
||||
router.route("/news/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOneNews);
|
||||
export default router;
|
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 620 KiB |
Before Width: | Height: | Size: 620 KiB |