fixed legal content api

This commit is contained in:
syedmujahidahmed 2024-03-28 12:40:38 +05:30
parent fd6a8e9c9b
commit 608cc318a6
2 changed files with 93 additions and 41 deletions

View File

@ -51,15 +51,23 @@ export const getTermsAndCondition = async (req, res) => {
export const updateTermsAndConditions = async (req, res) => {
try {
if (!req?.user) return res.status(400).json({ message: "please login !" });
// console.log(req?.user)
// new content
const { content } = req.body;
const termsAndCondition = await TermsAndCondition.findOneAndUpdate(
{
addedBy: req.user._id,
},
{
// id of the terms and conndition document
const id = req.query.id;
// object for updated terms and conndition data
const updatedTermsData = {
termsAndContionContent: content,
addedBy: req.user._id
}
// update the terms and conndition in database
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
{ _id: id },
{ $set: updatedTermsData },
{ new: true }
);
res.status(200).json({
@ -80,23 +88,10 @@ export const RefundPolicy = async (req, res) => {
if (!req?.user) return res.status(400).json({ message: "please login !" });
// console.log(req?.user)
const { content } = req.body;
const findv = await Refundpolicy.findOne();
let refundPolicy;
if (findv) {
refundPolicy = await Refundpolicy.findOneAndUpdate(
{
addedBy: req.user._id,
},
{
Refundpolicy: content,
}
);
} else {
refundPolicy = await Refundpolicy.create({
const refundPolicy = await Refundpolicy.create({
addedBy: req.user._id,
Refundpolicy: content,
});
}
res.status(200).json({
success: true,
@ -130,6 +125,42 @@ export const getRefundPolicy = async (req, res) => {
}
};
// update refund policy
export const updateRefundPolicy = async (req, res) => {
try {
if (!req?.user) return res.status(400).json({ message: "please login !" });
const {content} = req.body;
// id of the refund policy document
const id = req.query.id;
// object for updated refund policy data
const updatedRefundPolicyData = {
Refundpolicy: content,
addedBy: req.user._id
}
// update the refund policy in database
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
{ _id: id },
{ $set: updatedRefundPolicyData },
{ new: true }
);
res.status(200).json({
success: true,
refundPolicy,
message: "updated successfully ",
});
} catch (error) {
res.status(500).json({
success: false,
message: error.message ? error.message : "Something went Wrong",
});
}
};
// Privacy policy controller functions
export const AddPrivacyAndPolicy = async (req, res) => {
@ -180,15 +211,24 @@ export const getPrivacyPolicy = async (req, res) => {
export const updatePrivacyPolicy = async (req, res) => {
try {
if (!req?.user) return res.status(400).json({ message: "please login !" });
// console.log(req?.user)
// new content
const { content } = req.body;
const privacyAndPolicy = await PrivacyAndPolicy.findOneAndUpdate(
{
addedBy: req.user._id,
},
{
// id of the privacy policy document
const id = req.query.id;
// object for updated privacy policy data
const updatedPrivacyPolicyData = {
privacyAndPolicyContent: content,
addedBy: req.user._id
}
// update the privacy policy in database
const privacyAndPolicy = await PrivacyAndPolicy.findByIdAndUpdate(
{ _id: id },
{ $set: updatedPrivacyPolicyData },
{ new: true }
);
res.status(200).json({
@ -254,15 +294,23 @@ export const getShipping = async (req, res) => {
export const updateShipping = async (req, res) => {
try {
if (!req?.user) return res.status(400).json({ message: "please login !" });
// console.log(req?.user)
// new content
const { content } = req.body;
const shipping = await Shipping.findOneAndUpdate(
{
addedBy: req.user._id,
},
{
// id of the shipping policy document
const id = req.query.id;
// object for updated shipping policy data
const updatedShippingData = {
shippingContent: content,
addedBy: req.user._id
}
// update the shipping policy in database
const shipping = await Shipping.findByIdAndUpdate(
{ _id: id },
{ $set: updatedShippingData },
{ new: true }
);
res.status(200).json({

View File

@ -11,6 +11,7 @@ import {
updatePrivacyPolicy,
updateShipping,
updateTermsAndConditions,
updateRefundPolicy
} from "./ContentController.js";
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
@ -46,7 +47,10 @@ router
router.route("/refund-policy").get(getRefundPolicy);
router
.route("/refund-policy")
.patch(isAuthenticatedUser, authorizeRoles("admin"), RefundPolicy);
.post(isAuthenticatedUser, authorizeRoles("admin"), RefundPolicy);
router
.route("/refund-policy-update")
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateRefundPolicy);
//
export default router;