make it betterlkjkfkf
This commit is contained in:
parent
abecdce4b7
commit
369c00158b
5
app.js
5
app.js
@ -40,7 +40,10 @@ app.use("/api", Event);
|
||||
//Offers
|
||||
import Offer from "./routes/OffersRoute.js"
|
||||
app.use("/api", Offer);
|
||||
//Offers
|
||||
//banner
|
||||
import banner from "./routes/bannerRoute.js"
|
||||
app.use("/api", banner);
|
||||
//cmp-Ristriction
|
||||
import cmpRistriction from "./routes/cmp-restriction-Route.js"
|
||||
app.use("/api", cmpRistriction);
|
||||
export default app;
|
98
controllers/cmp-restriction-Controller.js
Normal file
98
controllers/cmp-restriction-Controller.js
Normal file
@ -0,0 +1,98 @@
|
||||
import cmpRestrictionModel from "../models/cmp-restriction-model.js"
|
||||
|
||||
export const createRestriction = async (req, res) => {
|
||||
|
||||
try {
|
||||
// console.log(req.body)
|
||||
|
||||
const data = await cmpRestrictionModel.create(req.body);
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
msg: " create Restriction Successfully!!",
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to create Restriction !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
//get All
|
||||
export const getAllRestriction = async (req, res) => {
|
||||
|
||||
try {
|
||||
const Restriction = await cmpRestrictionModel.find();
|
||||
// console.log(news)
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Successfully!!",
|
||||
Restriction,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//get One
|
||||
export const getOneRestriction = async (req, res) => {
|
||||
|
||||
try {
|
||||
const CmpRes = await cmpRestrictionModel.findById(req.params.id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: " fetch Restriction Successfully!!",
|
||||
CmpRes,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to fetch !!"
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 3.update
|
||||
export const updateRestriction = async (req, res) => {
|
||||
try {
|
||||
// console.log(req.body)
|
||||
const newResData = {
|
||||
Abaut_Us: req.body.Abaut_Us,
|
||||
Terms_and_Conditions: req.body.Terms_and_Conditions,
|
||||
Privacy_Policy: req.body.Privacy_Policy,
|
||||
};
|
||||
|
||||
|
||||
|
||||
//req.user.id,
|
||||
const ModifyCmpRes = await cmpRestrictionModel.findByIdAndUpdate(req.params.id, newResData,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
// useFindAndModify: false,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
ModifyCmpRes
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: "Failled to UpDate Restriction!!"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
22
models/cmp-restriction-model.js
Normal file
22
models/cmp-restriction-model.js
Normal file
@ -0,0 +1,22 @@
|
||||
import mongoose from "mongoose"
|
||||
const cmpRisSchema = new mongoose.Schema(
|
||||
{
|
||||
Abaut_Us: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
|
||||
Terms_and_Conditions: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
Privacy_Policy: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
|
||||
|
||||
}, { timestamps: true }
|
||||
);
|
||||
const cmpRisModel = mongoose.model("cmp-res", cmpRisSchema);
|
||||
export default cmpRisModel;
|
18
routes/cmp-restriction-Route.js
Normal file
18
routes/cmp-restriction-Route.js
Normal file
@ -0,0 +1,18 @@
|
||||
import express from "express";
|
||||
import {
|
||||
// createRestriction,
|
||||
getAllRestriction,
|
||||
updateRestriction,
|
||||
getOneRestriction
|
||||
} from "../controllers/cmp-restriction-Controller.js"
|
||||
const router = express.Router();
|
||||
|
||||
// router.route("/restriction/create/").post(createRestriction)
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
|
||||
router.route("/restriction/getAll").get(getAllRestriction)
|
||||
router.route("/restriction/getOne/:id").get(getOneRestriction)
|
||||
router.route("/restriction/update/:id").put(isAuthenticatedUser, authorizeRoles('admin'), updateRestriction);
|
||||
|
||||
export default router;
|
||||
getAllRestriction
|
Loading…
Reference in New Issue
Block a user