cms
This commit is contained in:
parent
a2b3a3108e
commit
6129740a92
@ -8,7 +8,7 @@ export const createNews = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const files = req.files.image;
|
const files = req.files.image;
|
||||||
|
|
||||||
console.log(files.tempFilePath)
|
// console.log(files.tempFilePath)
|
||||||
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||||
folder: "cmp/News",
|
folder: "cmp/News",
|
||||||
},
|
},
|
||||||
|
@ -1,11 +1,31 @@
|
|||||||
import cmpRestrictionModel from "../models/cmp-restriction-model.js"
|
import cmpRestrictionModel from "../models/cmp-restriction-model.js"
|
||||||
|
import cloudinary from "cloudinary";
|
||||||
export const createRestriction = async (req, res) => {
|
export const createRestriction = async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// console.log(req.body)
|
|
||||||
|
|
||||||
const data = await cmpRestrictionModel.create(req.body);
|
const CMSData = {
|
||||||
|
title: req.body.title,
|
||||||
|
page_data: req.body.page_data,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (req.files) {
|
||||||
|
const files = req.files.image;
|
||||||
|
|
||||||
|
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||||
|
folder: "cmp/image",
|
||||||
|
},
|
||||||
|
function (error, result) { (result, error) });
|
||||||
|
CMSData.image = {
|
||||||
|
public_id: myCloud.public_id,
|
||||||
|
url: myCloud.url,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await cmpRestrictionModel.create(
|
||||||
|
CMSData
|
||||||
|
);
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: " create Restriction Successfully!!",
|
msg: " create Restriction Successfully!!",
|
||||||
@ -63,36 +83,84 @@ export const getOneRestriction = async (req, res) => {
|
|||||||
// 3.update
|
// 3.update
|
||||||
export const updateRestriction = async (req, res) => {
|
export const updateRestriction = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// console.log(req.body)
|
if (!req.params.id) {
|
||||||
const newResData = {
|
return res.status(404).json({
|
||||||
About_Us: req.body.About_Us,
|
msg: "CMS Id Not Found!"
|
||||||
Terms_and_Conditions: req.body.Terms_and_Conditions,
|
});
|
||||||
Privacy_Policy: req.body.Privacy_Policy,
|
}
|
||||||
|
const CMSData = {
|
||||||
|
title: req.body.title,
|
||||||
|
page_data: req.body.page_data,
|
||||||
};
|
};
|
||||||
|
if (req.files) {
|
||||||
|
const getCms = await cmpRestrictionModel.findById(req.params.id);
|
||||||
|
//delete from cloudinary
|
||||||
|
if (getCms.image.public_id) {
|
||||||
|
const imageId = getCms.image.public_id;
|
||||||
|
await cloudinary.uploader.destroy(imageId)
|
||||||
|
}
|
||||||
|
const files = req.files.image;
|
||||||
|
|
||||||
|
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
|
||||||
|
folder: "cmp/image",
|
||||||
|
},
|
||||||
|
function (error, result) { (result, error) });
|
||||||
|
CMSData.image = {
|
||||||
|
public_id: myCloud.public_id,
|
||||||
|
url: myCloud.url,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const ModifyCms = await cmpRestrictionModel.findByIdAndUpdate(req.params.id, CMSData,
|
||||||
//req.user.id,
|
|
||||||
const ModifyCmpRes = await cmpRestrictionModel.findByIdAndUpdate(req.params.id, newResData,
|
|
||||||
|
|
||||||
{ new: true }
|
{ new: true }
|
||||||
// runValidators: true,
|
|
||||||
// useFindAndModify: false,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
ModifyCmpRes
|
ModifyCms
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
// console.log(error)
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
success: false,
|
success: false,
|
||||||
msg: "Failled to UpDate Restriction!!"
|
msg: "Failled to UpDate !!"
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//delete
|
||||||
|
export const deleteCms = async (req, res) => {
|
||||||
|
|
||||||
|
try {
|
||||||
|
//delete image from cloudinary
|
||||||
|
const getCms = await cmpRestrictionModel.findById(req.params.id);
|
||||||
|
|
||||||
|
if (getCms.image.public_id) {
|
||||||
|
const imageId = getCms.image.public_id;
|
||||||
|
await cloudinary.uploader.destroy(imageId)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------//
|
||||||
|
const Cms = await cmpRestrictionModel.findByIdAndDelete(req.params.id)
|
||||||
|
if (!Cms) {
|
||||||
|
return res.status(400).json({ message: 'CMS Not Found' });
|
||||||
|
}
|
||||||
|
await Cms.remove();
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: "CMS Deleted Successfully!!",
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
msg: "Failled to Delete !!"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
import mongoose from "mongoose"
|
import mongoose from "mongoose"
|
||||||
const cmpRisSchema = new mongoose.Schema(
|
const cmpRisSchema = new mongoose.Schema(
|
||||||
{
|
{
|
||||||
About_Us: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
page_data: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
image:
|
||||||
|
{
|
||||||
|
public_id: {
|
||||||
|
type: String,
|
||||||
|
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
Terms_and_Conditions: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
Privacy_Policy: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
}, { timestamps: true }
|
}, { timestamps: true }
|
||||||
|
@ -3,16 +3,19 @@ import {
|
|||||||
createRestriction,
|
createRestriction,
|
||||||
getAllRestriction,
|
getAllRestriction,
|
||||||
updateRestriction,
|
updateRestriction,
|
||||||
getOneRestriction
|
getOneRestriction,
|
||||||
|
deleteCms
|
||||||
} from "../controllers/cmp-restriction-Controller.js"
|
} from "../controllers/cmp-restriction-Controller.js"
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.route("/restriction/create/").post(createRestriction)
|
|
||||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||||
|
router.route("/restriction/cms/create/").post(isAuthenticatedUser, authorizeRoles('admin'), createRestriction)
|
||||||
|
|
||||||
router.route("/restriction/getAll").get(getAllRestriction)
|
router.route("/restriction/getAll").get(getAllRestriction)
|
||||||
router.route("/restriction/getOne/:id").get(getOneRestriction)
|
router.route("/restriction/getOne/:id").get(getOneRestriction)
|
||||||
router.route("/restriction/update/:id").put(isAuthenticatedUser, authorizeRoles('admin'), updateRestriction);
|
router.route("/restriction/cms/update/:id").put(isAuthenticatedUser, authorizeRoles('admin'), updateRestriction);
|
||||||
|
router.route("/restriction/cms/delete/:id").delete(isAuthenticatedUser, authorizeRoles('admin'), deleteCms);
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
getAllRestriction
|
getAllRestriction
|
Loading…
Reference in New Issue
Block a user