make it better
@ -4,6 +4,7 @@ import cloudinary from "cloudinary";
|
|||||||
export const createOffer = async (req, res) => {
|
export const createOffer = async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
//console.log(req.body)
|
||||||
const files = req.files.image;
|
const files = req.files.image;
|
||||||
|
|
||||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||||
|
@ -4,11 +4,8 @@ export const createDirectory = async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let images;
|
let images;
|
||||||
// console.log(req.body)
|
|
||||||
// console.log(req.body.image)
|
|
||||||
if (req.files) {
|
if (req.files) {
|
||||||
const files = req.files.image;
|
const files = req.files.image;
|
||||||
// console.log(files)
|
|
||||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||||
folder: "cmp/image",
|
folder: "cmp/image",
|
||||||
},
|
},
|
||||||
@ -116,7 +113,19 @@ export const updateDirectory = async (req, res) => {
|
|||||||
// };
|
// };
|
||||||
// console.log(newCategoryData)
|
// console.log(newCategoryData)
|
||||||
//req.user.id,
|
//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,
|
const ModifyDirectory = await directoryModel.findByIdAndUpdate(req.params.id, req.body,
|
||||||
|
|
||||||
{ new: true }
|
{ new: true }
|
||||||
|
@ -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,
|
||||||
|
});
|
||||||
|
});
|
@ -8,6 +8,21 @@ import {
|
|||||||
} from "../controllers/directoryController.js"
|
} from "../controllers/directoryController.js"
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
import { isAuthenticatedUser } from "../middlewares/auth.js"
|
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/create/").post(createDirectory)
|
||||||
router.route("/directory/getAll/").get(getAllDirectory)
|
router.route("/directory/getAll/").get(getAllDirectory)
|
||||||
router.route("/directory/getOne/:id").get(getOneDirectory)
|
router.route("/directory/getOne/:id").get(getOneDirectory)
|
||||||
|
@ -8,7 +8,8 @@ import {
|
|||||||
getUserDetails,
|
getUserDetails,
|
||||||
updatePassword,
|
updatePassword,
|
||||||
updateProfile,
|
updateProfile,
|
||||||
getSingleUser
|
getSingleUser,
|
||||||
|
getAllUser
|
||||||
} from "../controllers/userController.js"
|
} from "../controllers/userController.js"
|
||||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.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/logout").get(logout);
|
||||||
|
|
||||||
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
||||||
|
router
|
||||||
|
.route("/admin/users")
|
||||||
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
|
||||||
router
|
router
|
||||||
.route("/admin/user/:id")
|
.route("/admin/user/:id")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getSingleUser)
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getSingleUser)
|
||||||
|
BIN
tmp/tmp-1-1656326811580
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
tmp/tmp-1-1656329313855
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-1-1656331417302
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-1-1656331825681
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
tmp/tmp-1-1656331967729
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1656332014241
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1656332168853
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1656332490138
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1656391298865
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-1-1656392059110
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1656329565101
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-2-1656332016371
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-2-1656332619726
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-2-1656391417571
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-3-1656329696255
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
tmp/tmp-3-1656391672696
Normal file
After Width: | Height: | Size: 80 KiB |