diff --git a/controllers/OffersController.js b/controllers/OffersController.js index 43f20b1..22eaced 100644 --- a/controllers/OffersController.js +++ b/controllers/OffersController.js @@ -4,6 +4,7 @@ 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, { diff --git a/controllers/directoryController.js b/controllers/directoryController.js index 30102e7..5ff2e5f 100644 --- a/controllers/directoryController.js +++ b/controllers/directoryController.js @@ -4,11 +4,8 @@ export const createDirectory = async (req, res) => { try { let images; - // console.log(req.body) - // console.log(req.body.image) if (req.files) { const files = req.files.image; - // console.log(files) const myCloud = await cloudinary.uploader.upload(files.tempFilePath, { folder: "cmp/image", }, @@ -116,7 +113,19 @@ export const updateDirectory = async (req, res) => { // }; // console.log(newCategoryData) //req.user.id, - + 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 } diff --git a/controllers/userController.js b/controllers/userController.js index 09f4f05..0b0d50d 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -245,3 +245,13 @@ export const updateProfile = catchAsyncErrors(async (req, res, next) => { }); }); +// 9.Get all users(admin) +export const getAllUser = catchAsyncErrors(async (req, res, next) => { + + const users = await User.find()//.select('-role'); + + res.status(200).json({ + success: true, + users, + }); +}); \ No newline at end of file diff --git a/routes/directoryRoute.js b/routes/directoryRoute.js index ceed28d..eb10d30 100644 --- a/routes/directoryRoute.js +++ b/routes/directoryRoute.js @@ -8,6 +8,21 @@ import { } from "../controllers/directoryController.js" const router = express.Router(); import { isAuthenticatedUser } 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(createDirectory) router.route("/directory/getAll/").get(getAllDirectory) router.route("/directory/getOne/:id").get(getOneDirectory) diff --git a/routes/userRoute.js b/routes/userRoute.js index 379ce24..e574150 100644 --- a/routes/userRoute.js +++ b/routes/userRoute.js @@ -8,7 +8,8 @@ import { getUserDetails, updatePassword, updateProfile, - getSingleUser + getSingleUser, + getAllUser } from "../controllers/userController.js" import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js" @@ -25,6 +26,9 @@ router.route("/user/password/reset/:token").put(resetPassword); router.route("/user/logout").get(logout); router.route("/user/details").get(isAuthenticatedUser, getUserDetails); +router + .route("/admin/users") + .get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser); router .route("/admin/user/:id") .get(isAuthenticatedUser, authorizeRoles("admin"), getSingleUser) diff --git a/tmp/tmp-1-1656326811580 b/tmp/tmp-1-1656326811580 new file mode 100644 index 0000000..25c0dfa Binary files /dev/null and b/tmp/tmp-1-1656326811580 differ diff --git a/tmp/tmp-1-1656329313855 b/tmp/tmp-1-1656329313855 new file mode 100644 index 0000000..f61ad05 Binary files /dev/null and b/tmp/tmp-1-1656329313855 differ diff --git a/tmp/tmp-1-1656331417302 b/tmp/tmp-1-1656331417302 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-1-1656331417302 differ diff --git a/tmp/tmp-1-1656331825681 b/tmp/tmp-1-1656331825681 new file mode 100644 index 0000000..25c0dfa Binary files /dev/null and b/tmp/tmp-1-1656331825681 differ diff --git a/tmp/tmp-1-1656331967729 b/tmp/tmp-1-1656331967729 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1656331967729 differ diff --git a/tmp/tmp-1-1656332014241 b/tmp/tmp-1-1656332014241 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1656332014241 differ diff --git a/tmp/tmp-1-1656332168853 b/tmp/tmp-1-1656332168853 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1656332168853 differ diff --git a/tmp/tmp-1-1656332490138 b/tmp/tmp-1-1656332490138 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1656332490138 differ diff --git a/tmp/tmp-1-1656391298865 b/tmp/tmp-1-1656391298865 new file mode 100644 index 0000000..b9a863b Binary files /dev/null and b/tmp/tmp-1-1656391298865 differ diff --git a/tmp/tmp-1-1656392059110 b/tmp/tmp-1-1656392059110 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-1-1656392059110 differ diff --git a/tmp/tmp-2-1656329565101 b/tmp/tmp-2-1656329565101 new file mode 100644 index 0000000..25c7510 Binary files /dev/null and b/tmp/tmp-2-1656329565101 differ diff --git a/tmp/tmp-2-1656332016371 b/tmp/tmp-2-1656332016371 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-2-1656332016371 differ diff --git a/tmp/tmp-2-1656332619726 b/tmp/tmp-2-1656332619726 new file mode 100644 index 0000000..6fb99c9 Binary files /dev/null and b/tmp/tmp-2-1656332619726 differ diff --git a/tmp/tmp-2-1656391417571 b/tmp/tmp-2-1656391417571 new file mode 100644 index 0000000..25c7510 Binary files /dev/null and b/tmp/tmp-2-1656391417571 differ diff --git a/tmp/tmp-3-1656329696255 b/tmp/tmp-3-1656329696255 new file mode 100644 index 0000000..25c0dfa Binary files /dev/null and b/tmp/tmp-3-1656329696255 differ diff --git a/tmp/tmp-3-1656391672696 b/tmp/tmp-3-1656391672696 new file mode 100644 index 0000000..62743be Binary files /dev/null and b/tmp/tmp-3-1656391672696 differ