make it betterlkjkf
@ -4,8 +4,9 @@ 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;
|
||||||
|
// console.log(req.body)
|
||||||
// console.log(files)
|
// 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",
|
||||||
@ -24,6 +25,7 @@ export const createOffer = async (req, res) => {
|
|||||||
bisunessName
|
bisunessName
|
||||||
|
|
||||||
});
|
});
|
||||||
|
// console.log(data)
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: " create Offer Successfully!!",
|
msg: " create Offer Successfully!!",
|
||||||
|
@ -13,10 +13,11 @@ export const createBanner = async (req, res) => {
|
|||||||
folder: "cmp/image",
|
folder: "cmp/image",
|
||||||
},
|
},
|
||||||
function (error, result) { (result, error) });
|
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({
|
const data = await Banners.create({
|
||||||
title,
|
title,
|
||||||
|
subTitle,
|
||||||
image: {
|
image: {
|
||||||
public_id: myCloud.public_id,
|
public_id: myCloud.public_id,
|
||||||
url: myCloud.secure_url,
|
url: myCloud.secure_url,
|
||||||
@ -84,6 +85,8 @@ export const updateBanner = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const newBannerData = {
|
const newBannerData = {
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
|
subTitle: req.body.subTitle,
|
||||||
|
|
||||||
section: req.body.section,
|
section: req.body.section,
|
||||||
startDate: req.body.startDate,
|
startDate: req.body.startDate,
|
||||||
endDate: req.body.endDate,
|
endDate: req.body.endDate,
|
||||||
|
@ -4,27 +4,40 @@ import ErrorHander from "../Utils/errorhander.js"
|
|||||||
|
|
||||||
export const isAuthenticatedUser = async (req, res, next) => {
|
export const isAuthenticatedUser = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { token } = req.cookies;
|
// const { token } = req.cookies;
|
||||||
//const getToken = req.headers;
|
const getToken = req.headers;
|
||||||
|
|
||||||
// // console.log(getToken.authorization)
|
// // console.log(getToken.authorization)
|
||||||
// console.log(token)
|
// console.log(getToken)
|
||||||
|
|
||||||
// //remove Bearer from token
|
// //remove Bearer from token
|
||||||
// const token = getToken.authorization.slice(7);
|
const fronttoken = getToken.authorization.slice(7);
|
||||||
// // console.log(token)
|
//console.log(token)
|
||||||
|
|
||||||
if (!token) {
|
if (!fronttoken) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Login to Access this resource",
|
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)
|
// 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)
|
// console.log(user)
|
||||||
req.user = user;
|
req.user = fuser;
|
||||||
// console.log(req.user)
|
// console.log(req.user)
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
@ -5,6 +5,10 @@ const bannerSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
subTitle: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
image:
|
image:
|
||||||
{
|
{
|
||||||
public_id: {
|
public_id: {
|
||||||
|
@ -7,10 +7,11 @@ import {
|
|||||||
getOneOffer
|
getOneOffer
|
||||||
} from "../controllers/OffersController.js"
|
} from "../controllers/OffersController.js"
|
||||||
const router = express.Router();
|
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/getAll/").get(getAllOffer)
|
||||||
router.route("/offer/getOne/:id").get(getOneOffer)
|
router.route("/offer/getOne/:id").get(getOneOffer)
|
||||||
router.route("/offer/update/:id").put(updateOffer);
|
router.route("/offer/update/:id").put(isAuthenticatedUser, authorizeRoles("admin"), updateOffer);
|
||||||
router.route("/offer/delete/:id").delete(deleteOffer);
|
router.route("/offer/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOffer);
|
||||||
export default router;
|
export default router;
|
BIN
tmp/tmp-1-1655787766073
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-1-1655793757214
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1655793848440
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-1-1655794786361
Normal file
After Width: | Height: | Size: 1.1 MiB |
BIN
tmp/tmp-1-1655795259131
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-1-1655826962511
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-2-1655794867002
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
tmp/tmp-2-1655795481957
Normal file
After Width: | Height: | Size: 1.7 MiB |
BIN
tmp/tmp-2-1655826995622
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-3-1655795787029
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
tmp/tmp-3-1655827126460
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
tmp/tmp-4-1655796153961
Normal file
After Width: | Height: | Size: 620 KiB |
BIN
tmp/tmp-4-1655827217124
Normal file
After Width: | Height: | Size: 1.4 MiB |