make it betterlkjkf

This commit is contained in:
pawan-dot 2022-06-21 21:34:57 +05:30
parent a8d6c78334
commit 16dcb92f04
18 changed files with 37 additions and 14 deletions

View File

@ -4,8 +4,9 @@ import cloudinary from "cloudinary";
export const createOffer = async (req, res) => {
try {
// console.log(req.body)
const files = req.files.image;
// console.log(req.body)
// console.log(files)
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
folder: "cmp/image",
@ -24,6 +25,7 @@ export const createOffer = async (req, res) => {
bisunessName
});
// console.log(data)
res.status(201).json({
success: true,
msg: " create Offer Successfully!!",

View File

@ -13,10 +13,11 @@ export const createBanner = async (req, res) => {
folder: "cmp/image",
},
function (error, result) { (result, error) });
const { title, section, startDate, endDate } = req.body;
const { title, section, startDate, endDate, subTitle } = req.body;
const data = await Banners.create({
title,
subTitle,
image: {
public_id: myCloud.public_id,
url: myCloud.secure_url,
@ -84,6 +85,8 @@ export const updateBanner = async (req, res) => {
try {
const newBannerData = {
title: req.body.title,
subTitle: req.body.subTitle,
section: req.body.section,
startDate: req.body.startDate,
endDate: req.body.endDate,

View File

@ -4,27 +4,40 @@ import ErrorHander from "../Utils/errorhander.js"
export const isAuthenticatedUser = async (req, res, next) => {
try {
const { token } = req.cookies;
//const getToken = req.headers;
// const { token } = req.cookies;
const getToken = req.headers;
// // console.log(getToken.authorization)
// console.log(token)
// console.log(getToken)
// //remove Bearer from token
// const token = getToken.authorization.slice(7);
// // console.log(token)
const fronttoken = getToken.authorization.slice(7);
//console.log(token)
if (!token) {
if (!fronttoken) {
return res.status(400).json({
success: false,
message: "Login to Access this resource",
});
}
// if (!fronttoken) {
// return res.status(400).json({
// success: false,
// message: "Login to Access this resource",
// });
// }
const decoded = jwt.verify(token, process.env.JWT_SECRET);
//const decoded = jwt.verify(token, process.env.JWT_SECRET);
const frontdecoded = jwt.verify(fronttoken, process.env.JWT_SECRET);
// console.log(decoded)
const user = await User.findById(decoded.id);
//const user = await User.findById(decoded.id);
const fuser = await User.findById(frontdecoded.id);
// if (fuser != null) {
// req.user = fuser;
// //console.log(fuser)
// }
// console.log(user)
req.user = user;
req.user = fuser;
// console.log(req.user)
next();

View File

@ -5,6 +5,10 @@ const bannerSchema = new mongoose.Schema(
type: String,
required: true
},
subTitle: {
type: String,
required: true
},
image:
{
public_id: {

View File

@ -7,10 +7,11 @@ import {
getOneOffer
} from "../controllers/OffersController.js"
const router = express.Router();
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
router.route("/offer/create/").post(createOffer)
router.route("/offer/create/").post(isAuthenticatedUser, authorizeRoles("admin"), createOffer)
router.route("/offer/getAll/").get(getAllOffer)
router.route("/offer/getOne/:id").get(getOneOffer)
router.route("/offer/update/:id").put(updateOffer);
router.route("/offer/delete/:id").delete(deleteOffer);
router.route("/offer/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateOffer);
router.route("/offer/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOffer);
export default router;

BIN
tmp/tmp-1-1655787766073 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
tmp/tmp-1-1655793757214 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1655793848440 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-1-1655794786361 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
tmp/tmp-1-1655795259131 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
tmp/tmp-1-1655826962511 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

BIN
tmp/tmp-2-1655794867002 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
tmp/tmp-2-1655795481957 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

BIN
tmp/tmp-2-1655826995622 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-3-1655795787029 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
tmp/tmp-3-1655827126460 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
tmp/tmp-4-1655796153961 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB

BIN
tmp/tmp-4-1655827217124 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB