make it better

This commit is contained in:
pawan-dot 2022-06-28 11:59:30 +05:30
parent f3a70b0fe9
commit 86814efc11
21 changed files with 44 additions and 5 deletions

View File

@ -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, {

View File

@ -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 }

View File

@ -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,
});
});

View File

@ -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)

View File

@ -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)

BIN
tmp/tmp-1-1656326811580 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
tmp/tmp-1-1656329313855 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-1-1656331417302 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-1-1656331825681 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
tmp/tmp-1-1656331967729 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1656332014241 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1656332168853 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1656332490138 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1656391298865 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
tmp/tmp-1-1656392059110 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-2-1656329565101 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

BIN
tmp/tmp-2-1656332016371 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-2-1656332619726 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-2-1656391417571 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

BIN
tmp/tmp-3-1656329696255 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
tmp/tmp-3-1656391672696 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB