about us controller and shipping update api
This commit is contained in:
parent
61d3835cc9
commit
82159a7449
22
resources/Content/AboutUsModel.js
Normal file
22
resources/Content/AboutUsModel.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const aboutUsSchema = new Schema(
|
||||||
|
{
|
||||||
|
aboutUsContent: {
|
||||||
|
type: String,
|
||||||
|
default:''
|
||||||
|
},
|
||||||
|
addedBy: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const AboutUs = model(
|
||||||
|
"AboutUs",
|
||||||
|
aboutUsSchema
|
||||||
|
);
|
@ -2,6 +2,7 @@ import { PrivacyAndPolicy } from "./PrivacyPolicyModel.js";
|
|||||||
import { Refundpolicy } from "./RefundModel.js";
|
import { Refundpolicy } from "./RefundModel.js";
|
||||||
import { Shipping } from "./ShippingModel.js";
|
import { Shipping } from "./ShippingModel.js";
|
||||||
import { TermsAndCondition } from "./TermsandConditonModel.js";
|
import { TermsAndCondition } from "./TermsandConditonModel.js";
|
||||||
|
import { AboutUs } from './AboutUsModel.js'
|
||||||
|
|
||||||
export const AddTermsAndConditions = async (req, res) => {
|
export const AddTermsAndConditions = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@ -51,24 +52,24 @@ export const getTermsAndCondition = async (req, res) => {
|
|||||||
export const updateTermsAndConditions = async (req, res) => {
|
export const updateTermsAndConditions = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// new content
|
// new content
|
||||||
const { content } = req.body;
|
const { content } = req.body;
|
||||||
|
|
||||||
// id of the terms and conndition document
|
// id of the terms and conndition document
|
||||||
const id = req.query.id;
|
const id = req.query.id;
|
||||||
|
|
||||||
// object for updated terms and conndition data
|
// object for updated terms and conndition data
|
||||||
const updatedTermsData = {
|
const updatedTermsData = {
|
||||||
termsAndContionContent: content,
|
termsAndContionContent: content,
|
||||||
addedBy: req.user._id
|
addedBy: req.user._id
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the terms and conndition in database
|
// update the terms and conndition in database
|
||||||
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
|
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
|
||||||
{ _id: id },
|
{ _id: id },
|
||||||
{ $set: updatedTermsData },
|
{ $set: updatedTermsData },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -88,10 +89,10 @@ export const RefundPolicy = async (req, res) => {
|
|||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
// console.log(req?.user)
|
// console.log(req?.user)
|
||||||
const { content } = req.body;
|
const { content } = req.body;
|
||||||
const refundPolicy = await Refundpolicy.create({
|
const refundPolicy = await Refundpolicy.create({
|
||||||
addedBy: req.user._id,
|
addedBy: req.user._id,
|
||||||
Refundpolicy: content,
|
Refundpolicy: content,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -130,22 +131,22 @@ export const updateRefundPolicy = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
const {content} = req.body;
|
const { content } = req.body;
|
||||||
// id of the refund policy document
|
// id of the refund policy document
|
||||||
const id = req.query.id;
|
const id = req.query.id;
|
||||||
|
|
||||||
// object for updated refund policy data
|
// object for updated refund policy data
|
||||||
const updatedRefundPolicyData = {
|
const updatedRefundPolicyData = {
|
||||||
Refundpolicy: content,
|
Refundpolicy: content,
|
||||||
addedBy: req.user._id
|
addedBy: req.user._id
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the refund policy in database
|
// update the refund policy in database
|
||||||
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
|
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
|
||||||
{ _id: id },
|
{ _id: id },
|
||||||
{ $set: updatedRefundPolicyData },
|
{ $set: updatedRefundPolicyData },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -305,7 +306,7 @@ export const updateShipping = async (req, res) => {
|
|||||||
shippingContent: content,
|
shippingContent: content,
|
||||||
addedBy: req.user._id
|
addedBy: req.user._id
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the shipping policy in database
|
// update the shipping policy in database
|
||||||
const shipping = await Shipping.findByIdAndUpdate(
|
const shipping = await Shipping.findByIdAndUpdate(
|
||||||
{ _id: id },
|
{ _id: id },
|
||||||
@ -325,3 +326,88 @@ export const updateShipping = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// About us controller functions
|
||||||
|
|
||||||
|
export const AddAboutUs = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
req.body.user = req.user._id;
|
||||||
|
const { content } = req.body;
|
||||||
|
const aboutUs = await AboutUs.create({
|
||||||
|
aboutUs: content,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
aboutUs,
|
||||||
|
message: "Added successfully",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getAboutUs = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
const aboutUs = await AboutUs.find();
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
aboutUs,
|
||||||
|
message: "Found successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateAboutUs = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
|
||||||
|
// new content
|
||||||
|
const { content } = req.body;
|
||||||
|
|
||||||
|
// id of the about us document
|
||||||
|
const id = req.query.id;
|
||||||
|
|
||||||
|
// object for updated about us data
|
||||||
|
const updatedAboutUsData = {
|
||||||
|
aboutUsContent: content,
|
||||||
|
addedBy: req.user._id
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the about us in database
|
||||||
|
const aboutUs = await AboutUs.findByIdAndUpdate(
|
||||||
|
{ _id: id },
|
||||||
|
{ $set: updatedAboutUsData },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
aboutUs,
|
||||||
|
message: "updated successfully ",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@ import {
|
|||||||
updatePrivacyPolicy,
|
updatePrivacyPolicy,
|
||||||
updateShipping,
|
updateShipping,
|
||||||
updateTermsAndConditions,
|
updateTermsAndConditions,
|
||||||
updateRefundPolicy
|
updateRefundPolicy,
|
||||||
|
AddAboutUs,
|
||||||
|
getAboutUs,
|
||||||
|
updateAboutUs
|
||||||
} from "./ContentController.js";
|
} from "./ContentController.js";
|
||||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
|
|
||||||
@ -51,6 +54,13 @@ router
|
|||||||
router
|
router
|
||||||
.route("/refund-policy-update")
|
.route("/refund-policy-update")
|
||||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateRefundPolicy);
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateRefundPolicy);
|
||||||
//
|
//about us
|
||||||
|
router
|
||||||
|
.route("/about-us")
|
||||||
|
.post(isAuthenticatedUser, authorizeRoles("admin"), AddAboutUs);
|
||||||
|
router.route("/about-us").get(getAboutUs);
|
||||||
|
router
|
||||||
|
.route("/about-us-update")
|
||||||
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateAboutUs);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -94,7 +94,7 @@ export const deleteSelfShippingAddress = async (req, res) => {
|
|||||||
await address.remove();
|
await address.remove();
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "shipping Address Deleted Successfully!!",
|
message: "Shipping Address Deleted Successfully!",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@ -109,3 +109,105 @@ export const deleteSelfShippingAddress = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// update shipping addresss
|
||||||
|
export const updateShippingAddress = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
first_Name,
|
||||||
|
last_Name,
|
||||||
|
phone_Number,
|
||||||
|
street,
|
||||||
|
city,
|
||||||
|
state,
|
||||||
|
postalCode,
|
||||||
|
country,
|
||||||
|
} = req.body;
|
||||||
|
const _id = req.params.id;
|
||||||
|
if (!req.params.id)
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ message: "please Provide shipping Address Id" });
|
||||||
|
const getselfAddress = await shippingAddress.findById(req.params.id);
|
||||||
|
if (!getselfAddress) {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
message: "No shipping Address Found!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
switch (true) {
|
||||||
|
//validation
|
||||||
|
case !first_Name: {
|
||||||
|
return res.status(404).json({ msg: "please provide first_Name" });
|
||||||
|
}
|
||||||
|
case !last_Name: {
|
||||||
|
return res.status(404).json({ msg: "please provide last_Name" });
|
||||||
|
}
|
||||||
|
case !phone_Number: {
|
||||||
|
return res.status(404).json({ msg: "please provide phone_Number" });
|
||||||
|
}
|
||||||
|
case !street: {
|
||||||
|
return res.status(404).json({ msg: "please provide street" });
|
||||||
|
}
|
||||||
|
case !city: {
|
||||||
|
return res.status(404).json({ msg: "please provide city" });
|
||||||
|
}
|
||||||
|
case !state: {
|
||||||
|
return res.status(404).json({ msg: "please provide state" });
|
||||||
|
}
|
||||||
|
case !postalCode: {
|
||||||
|
return res.status(404).json({ msg: "please provide postalCode" });
|
||||||
|
}
|
||||||
|
case !country: {
|
||||||
|
return res.status(404).json({ msg: "please provide country" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const updateAddressData = {
|
||||||
|
first_Name,
|
||||||
|
last_Name,
|
||||||
|
phone_Number,
|
||||||
|
street,
|
||||||
|
city,
|
||||||
|
state,
|
||||||
|
postalCode,
|
||||||
|
country,
|
||||||
|
}
|
||||||
|
const updateShippingAddress = await shippingAddress.findByIdAndUpdate(
|
||||||
|
{ _id: _id },
|
||||||
|
{ $set: updateAddressData },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
updateShippingAddress,
|
||||||
|
message: "Shipping Address updated",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getSingleSippingAddress = async (req, res) => {
|
||||||
|
try {
|
||||||
|
let _id = req.params.id
|
||||||
|
const address = await shippingAddress.findById({ _id: _id })
|
||||||
|
|
||||||
|
if (address) {
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
address,
|
||||||
|
message: "Shipping Address Fetched",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -3,6 +3,8 @@ import {
|
|||||||
AddshippingAddress,
|
AddshippingAddress,
|
||||||
getSingleUserSippingAddress,
|
getSingleUserSippingAddress,
|
||||||
deleteSelfShippingAddress,
|
deleteSelfShippingAddress,
|
||||||
|
updateShippingAddress,
|
||||||
|
getSingleSippingAddress,
|
||||||
} from "./ShippingAddressController.js";
|
} from "./ShippingAddressController.js";
|
||||||
import { isAuthenticatedUser } from "../../middlewares/auth.js";
|
import { isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -16,4 +18,11 @@ router
|
|||||||
.route("/delete/:id")
|
.route("/delete/:id")
|
||||||
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/update/:id")
|
||||||
|
.patch(isAuthenticatedUser, updateShippingAddress);
|
||||||
|
router
|
||||||
|
.route("/get/:id")
|
||||||
|
.get(isAuthenticatedUser, getSingleSippingAddress);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
Reference in New Issue
Block a user