From 369c00158bd60ba67fb70d4b48c903ac6124c63d Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Wed, 22 Jun 2022 16:45:48 +0530 Subject: [PATCH] make it betterlkjkfkf --- app.js | 5 +- controllers/cmp-restriction-Controller.js | 98 +++++++++++++++++++++++ models/cmp-restriction-model.js | 22 +++++ routes/cmp-restriction-Route.js | 18 +++++ 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 controllers/cmp-restriction-Controller.js create mode 100644 models/cmp-restriction-model.js create mode 100644 routes/cmp-restriction-Route.js diff --git a/app.js b/app.js index 95712c9..e40f740 100644 --- a/app.js +++ b/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; \ No newline at end of file diff --git a/controllers/cmp-restriction-Controller.js b/controllers/cmp-restriction-Controller.js new file mode 100644 index 0000000..dffb252 --- /dev/null +++ b/controllers/cmp-restriction-Controller.js @@ -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!!" + + }); + } + +}; + diff --git a/models/cmp-restriction-model.js b/models/cmp-restriction-model.js new file mode 100644 index 0000000..ccd788b --- /dev/null +++ b/models/cmp-restriction-model.js @@ -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; \ No newline at end of file diff --git a/routes/cmp-restriction-Route.js b/routes/cmp-restriction-Route.js new file mode 100644 index 0000000..d3919dd --- /dev/null +++ b/routes/cmp-restriction-Route.js @@ -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 \ No newline at end of file