make it betterlkjkfkf

This commit is contained in:
pawan-dot 2022-06-22 16:45:48 +05:30
parent abecdce4b7
commit 369c00158b
4 changed files with 142 additions and 1 deletions

5
app.js
View File

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

View 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!!"
});
}
};

View 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;

View 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