From 79ab25e447d56b87b79652e39aaed45365497022 Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Fri, 28 Oct 2022 13:08:59 +0530 Subject: [PATCH] self directory --- controllers/bannerController.js | 13 +++++++------ controllers/directoryController.js | 4 ++-- controllers/userController.js | 7 ++++++- models/bannerModel.js | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/controllers/bannerController.js b/controllers/bannerController.js index cd0d60e..7e2e63c 100644 --- a/controllers/bannerController.js +++ b/controllers/bannerController.js @@ -13,7 +13,7 @@ export const createBanner = async (req, res) => { }, function (error, result) { (result, error) }); - const { title, section, startDate, subSection, endDate, subTitle } = req.body; + const { title, startDate, endDate, subTitle } = req.body; const data = await Banners.create({ title, subTitle, @@ -21,10 +21,10 @@ export const createBanner = async (req, res) => { public_id: myCloud.public_id, url: myCloud.secure_url, }, - section, + // section, startDate, endDate, - subSection + // subSection }); @@ -85,12 +85,13 @@ export const getOneBanner = async (req, res) => { // 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, + // section: req.body.section, + // subSection: req.body.subSection, startDate: req.body.startDate, endDate: req.body.endDate, }; @@ -130,7 +131,7 @@ export const updateBanner = async (req, res) => { }); } catch (error) { - // console.log(error) + console.log(error) res.status(500).json({ success: false, msg: "Failled to UpDate Banner!!" diff --git a/controllers/directoryController.js b/controllers/directoryController.js index 3fcf5f2..9fea124 100644 --- a/controllers/directoryController.js +++ b/controllers/directoryController.js @@ -178,8 +178,8 @@ export const deleteOneDirectory = async (req, res) => { export const getSelfDirectory = async (req, res) => { try { - const directory = await directoryModel.findOne({ userId: req.user.id }); - // console.log(category) + const directory = await directoryModel.find({ userId: req.user.id }); + if (!directory) { return res.status(400).json({ message: 'No self directory exist ' }); } diff --git a/controllers/userController.js b/controllers/userController.js index 520f8c9..8a46948 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -197,11 +197,16 @@ export const getUserDetails = catchAsyncErrors(async (req, res, next) => { // 7.Get single user (admin) export const getSingleUser = catchAsyncErrors(async (req, res, next) => { + if (!req.params.id) { + return next( + new ErrorHander(`please send User ID`, 404) + ); + } const user = await User.findById(req.params.id); if (!user) { return next( - new ErrorHander(`User does not exist with Id: ${req.params.id}`) + new ErrorHander(`User does not exist with Id: ${req.params.id}`, 404) ); } diff --git a/models/bannerModel.js b/models/bannerModel.js index c6c7354..454ea3a 100644 --- a/models/bannerModel.js +++ b/models/bannerModel.js @@ -22,7 +22,7 @@ const bannerSchema = new mongoose.Schema( }, section: { type: String, - required: true + }, subSection: { type: String,