From 8218f2447dd850477f0d433900db0574314f731b Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Tue, 2 Apr 2024 14:59:19 +0530 Subject: [PATCH 1/4] get All Order Api Developed for Deshboard --- resources/Orders/orderController.js | 28 +++++++++++++++++++++++++++- resources/Orders/orderRoute.js | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/resources/Orders/orderController.js b/resources/Orders/orderController.js index 77dd538..9444e68 100644 --- a/resources/Orders/orderController.js +++ b/resources/Orders/orderController.js @@ -36,7 +36,33 @@ export const getAllOrder = async (req, res) => { }); } }; - +export const getOrders = async (req, res) => { + try { + const order = await Order.find({ + payment_status: "success", + }) + .populate({ + path: "user", + select: "name -_id", + }) + .populate({ + path: "shippingInfo.addressId", + }) + .sort({ updatedAt: -1 }); + if (order) { + res.status(201).json({ + success: true, + order, + message: "All Order Fetched", + }); + } + } catch (error) { + res.status(500).json({ + success: false, + message: error.message ? error.message : "Something went Wrong", + }); + } +}; export const getSingleOrder = async (req, res) => { try { if (!req.params.id) diff --git a/resources/Orders/orderRoute.js b/resources/Orders/orderRoute.js index 32cd99a..89721b8 100644 --- a/resources/Orders/orderRoute.js +++ b/resources/Orders/orderRoute.js @@ -2,6 +2,7 @@ import bodyParser from "body-parser"; import { deleteOneOrder, getAllOrder, + getOrders, getSingleOrder, getUserSelf, updateOrderStatusById, @@ -46,6 +47,9 @@ router.route("/user/self").get(isAuthenticatedUser, getUserSelf); router .route("/getAll/:status") .get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrder); + router + .route("/getAll/") + .get(isAuthenticatedUser, authorizeRoles("admin"), getOrders); router.route("/getOne/:id").get(isAuthenticatedUser, getSingleOrder); router.route("/change/status/:id").patch(updateOrderStatusById); From 076958eba6830f04b300f2636b16306cabd620fa Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Tue, 2 Apr 2024 15:03:34 +0530 Subject: [PATCH 2/4] updated package-lock.json from privious commit --- package-lock.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9bafc1a..a1f5970 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5417,7 +5417,8 @@ "cloudinary-core": { "version": "2.12.3", "resolved": "https://registry.npmjs.org/cloudinary-core/-/cloudinary-core-2.12.3.tgz", - "integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A==" + "integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A==", + "requires": {} }, "color-convert": { "version": "2.0.1", @@ -6660,7 +6661,8 @@ "multer-storage-cloudinary": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/multer-storage-cloudinary/-/multer-storage-cloudinary-4.0.0.tgz", - "integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA==" + "integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA==", + "requires": {} }, "mute-stream": { "version": "0.0.8", @@ -7893,7 +7895,8 @@ "ws": { "version": "7.4.6", "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==" + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "requires": {} }, "xregexp": { "version": "2.0.0", From ee5f7f94919fc7644b8f45519ac774b1a7329e4a Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:52:33 +0530 Subject: [PATCH 3/4] razerpay integration --- .../Orders/RazerPayCheckoutController.js | 120 +++++++++++++++--- resources/Orders/orderModel.js | 16 +++ 2 files changed, 120 insertions(+), 16 deletions(-) diff --git a/resources/Orders/RazerPayCheckoutController.js b/resources/Orders/RazerPayCheckoutController.js index c39b04f..fe4f436 100644 --- a/resources/Orders/RazerPayCheckoutController.js +++ b/resources/Orders/RazerPayCheckoutController.js @@ -56,15 +56,23 @@ export const checkout = async (req, res) => { const { address, cart, subtotal } = req.body; if (cart.length < 1) return res.status(400).json({ message: "cart is empty!" }); - switch (true) { - //validation - case !address: { - return res.status(404).json({ msg: "please provide shipping address" }); - } - case !subtotal: { - return res.status(404).json({ msg: "please provide product subtotal" }); - } - } + if (!address) + return res + .status(404) + .json({ message: "please select shipping address!" }); + if (!subtotal) + return res + .status(404) + .json({ message: "please provide product subtotal!" }); + // switch (true) { + // //validation + // case !address: { + // return res.status(404).json({ msg: "please select shipping address" }); + // } + // case !subtotal: { + // return res.status(404).json({ msg: "please provide product subtotal" }); + // } + // } let addss = await shippingAddress.findById(address); let shipping = { first_Name: addss.first_Name, @@ -77,12 +85,18 @@ export const checkout = async (req, res) => { country: addss.country, addressId: address, }; + // console.log("cart", cart[0]?.product?.gst); const orderItems = await cart.map((item) => ({ product: item.product._id, name: item.product.name, - price: item.product.total_amount, + price: item.product.price, + total_Amount: item.product.total_amount, + image: item.product.image, quantity: item.quantity, + gst_amount: item.product.gst_amount, + gst_rate: item.product.gst?.tax, + tax_Name: item.product.gst?.name, product_Subtotal: item.subtotal, })); @@ -130,7 +144,7 @@ export const paymentVerification = async (req, res) => { path: "user", select: "name email -_id", }); - console.log("findSameOrder", findSameOrder); + // console.log("findSameOrder", findSameOrder); if (findSameOrder) { (findSameOrder.razorpay_payment_id = razorpay_payment_id), // await Payment.create({ (findSameOrder.isPaid = true), @@ -143,7 +157,7 @@ export const paymentVerification = async (req, res) => { await findSameOrder.save(); } //send email to customer - + // console.log("findSameOrder", findSameOrder); await sendEmail({ to: `${findSameOrder?.user?.email}`, // Change to your recipient @@ -151,10 +165,84 @@ export const paymentVerification = async (req, res) => { subject: `Your Order #${findSameOrder?.orderID} Confirmation`, html: `

Welcome to Smellika - Let the Shopping Begin!

- Hi ${findSameOrder?.shippingInfo?.first_Name}, + Hi ${ + findSameOrder?.shippingInfo?.first_Name + }, -

Great news! Your order #${findSameOrder?.orderID} has been confirmed. Here are the details

-
+

Great news! Your order #${ + findSameOrder?.orderID + } has been confirmed. Here are the details

+

Shipping Address : ${ + findSameOrder?.shippingInfo?.first_Name + } ${findSameOrder?.shippingInfo?.last_Name} , ${ + findSameOrder?.shippingInfo?.street + } ${findSameOrder?.shippingInfo?.city} ${ + findSameOrder?.shippingInfo?.state + } ${findSameOrder?.shippingInfo?.country}, PIN-${ + findSameOrder?.shippingInfo?.postalCode + }, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}

+

Order Items :

+ + + + + + + + + + + + + + + + + + ${findSameOrder?.orderItems + ?.map( + (product, index) => ` + + + + + + + + + + + + + ` + ) + .join("")} + + + + + +
S No.Product NameImageQuantityPriceGST AmountSubTotal
${ + index + 1 + }${ + product.name + }${
+          product.name
+        }${ + product.quantity + }₹${ + product.price + }₹${ + product?.gst_amount + }₹${ + product.product_Subtotal + }
Total Amount :₹${ + findSameOrder?.total_amount + }
+ +
Best regards,
Team Smellika`, @@ -171,7 +259,7 @@ export const paymentVerification = async (req, res) => { // razorpay_signature, // }); - res.redirect(`http://localhost:5173/account`); + res.redirect(`https://smellika.com/shop`); // res.redirect( // `http://localhost:5173/cart/paymentsuccess?reference=${razorpay_payment_id}` // ); diff --git a/resources/Orders/orderModel.js b/resources/Orders/orderModel.js index 3268b67..c360aba 100644 --- a/resources/Orders/orderModel.js +++ b/resources/Orders/orderModel.js @@ -66,6 +66,10 @@ const orderSchema = new mongoose.Schema( type: Number, default: "", }, + total_Amount: { + type: Number, + default: "", + }, quantity: { type: Number, default: "", @@ -77,6 +81,18 @@ const orderSchema = new mongoose.Schema( type: Number, default: "", }, + gst_amount: { + type: Number, + default: "", + }, + gst_rate: { + type: Number, + default: "", + }, + tax_Name: { + type: String, + default: "", + }, product: { type: mongoose.Schema.ObjectId, ref: "Product", From 82159a7449a9ef0116a77b194db7287a92c3655a Mon Sep 17 00:00:00 2001 From: syedmujahidahmed Date: Wed, 3 Apr 2024 17:12:24 +0530 Subject: [PATCH 4/4] about us controller and shipping update api --- resources/Content/AboutUsModel.js | 22 +++ resources/Content/ContentController.js | 160 ++++++++++++++---- resources/Content/ContentRoutes.js | 14 +- .../ShippingAddressController.js | 104 +++++++++++- .../ShippingAddresses/ShippingAddressRoute.js | 9 + 5 files changed, 269 insertions(+), 40 deletions(-) create mode 100644 resources/Content/AboutUsModel.js diff --git a/resources/Content/AboutUsModel.js b/resources/Content/AboutUsModel.js new file mode 100644 index 0000000..ff2511e --- /dev/null +++ b/resources/Content/AboutUsModel.js @@ -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 +); diff --git a/resources/Content/ContentController.js b/resources/Content/ContentController.js index b366441..52c17fd 100644 --- a/resources/Content/ContentController.js +++ b/resources/Content/ContentController.js @@ -2,6 +2,7 @@ import { PrivacyAndPolicy } from "./PrivacyPolicyModel.js"; import { Refundpolicy } from "./RefundModel.js"; import { Shipping } from "./ShippingModel.js"; import { TermsAndCondition } from "./TermsandConditonModel.js"; +import { AboutUs } from './AboutUsModel.js' export const AddTermsAndConditions = async (req, res) => { try { @@ -51,24 +52,24 @@ export const getTermsAndCondition = async (req, res) => { export const updateTermsAndConditions = async (req, res) => { try { if (!req?.user) return res.status(400).json({ message: "please login !" }); - // new content - const { content } = req.body; + // new content + const { content } = req.body; - // id of the terms and conndition document - const id = req.query.id; - - // object for updated terms and conndition data - const updatedTermsData = { + // 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 } - ); + 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({ success: true, @@ -88,10 +89,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 refundPolicy = await Refundpolicy.create({ - addedBy: req.user._id, - Refundpolicy: content, - }); + const refundPolicy = await Refundpolicy.create({ + addedBy: req.user._id, + Refundpolicy: content, + }); res.status(200).json({ success: true, @@ -130,22 +131,22 @@ 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 } - ); + 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, @@ -305,7 +306,7 @@ export const updateShipping = async (req, res) => { shippingContent: content, addedBy: req.user._id } - + // update the shipping policy in database const shipping = await Shipping.findByIdAndUpdate( { _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", + }); + } +}; + + diff --git a/resources/Content/ContentRoutes.js b/resources/Content/ContentRoutes.js index eddc29a..71146c0 100644 --- a/resources/Content/ContentRoutes.js +++ b/resources/Content/ContentRoutes.js @@ -11,7 +11,10 @@ import { updatePrivacyPolicy, updateShipping, updateTermsAndConditions, - updateRefundPolicy + updateRefundPolicy, + AddAboutUs, + getAboutUs, + updateAboutUs } from "./ContentController.js"; import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js"; @@ -51,6 +54,13 @@ router router .route("/refund-policy-update") .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; diff --git a/resources/ShippingAddresses/ShippingAddressController.js b/resources/ShippingAddresses/ShippingAddressController.js index ae49f13..f0411ed 100644 --- a/resources/ShippingAddresses/ShippingAddressController.js +++ b/resources/ShippingAddresses/ShippingAddressController.js @@ -94,7 +94,7 @@ export const deleteSelfShippingAddress = async (req, res) => { await address.remove(); return res.status(200).json({ success: true, - message: "shipping Address Deleted Successfully!!", + message: "Shipping Address Deleted Successfully!", }); } else { 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", + }); + } +}; diff --git a/resources/ShippingAddresses/ShippingAddressRoute.js b/resources/ShippingAddresses/ShippingAddressRoute.js index 9d2a1db..d7b2b9b 100644 --- a/resources/ShippingAddresses/ShippingAddressRoute.js +++ b/resources/ShippingAddresses/ShippingAddressRoute.js @@ -3,6 +3,8 @@ import { AddshippingAddress, getSingleUserSippingAddress, deleteSelfShippingAddress, + updateShippingAddress, + getSingleSippingAddress, } from "./ShippingAddressController.js"; import { isAuthenticatedUser } from "../../middlewares/auth.js"; const router = express.Router(); @@ -16,4 +18,11 @@ router .route("/delete/:id") .delete(isAuthenticatedUser, deleteSelfShippingAddress); + router + .route("/update/:id") + .patch(isAuthenticatedUser, updateShippingAddress); + router + .route("/get/:id") + .get(isAuthenticatedUser, getSingleSippingAddress); + export default router;