resolved conflicts
This commit is contained in:
commit
539316a953
10
.env
10
.env
@ -12,12 +12,12 @@ CLOUDINARY_API_KEY = "877544192441588"
|
||||
CLOUDINARY_API_SECRET = "9paejuSC-fY5b0WoaUuSFURSnvM"
|
||||
WEBHOOK_SECRET_KEY="whsec_m9u7CFBCY1qWarhxq65CkII6egOBf20K"
|
||||
|
||||
STRIPE_SECRET_KEY="sk_test_51OhPRdSG6gbAOwcEid1GavJ4FTD0ZuHVTferdvJwKal77RlMtFJGBzL5GjtL0ie8ZJztsGjUWi8DWrnw1pDdDRGS005Hk0ahql"
|
||||
STRIPE_WEBHOOK_SECRET="whsec_dc9b9084fc764c806c8c5c06dd91de1ee809e9c8deab6d56e8e3ef2fc9c30c67"
|
||||
<<<<<<< HEAD
|
||||
# STRIPE_SECRET_KEY="sk_test_51OhPRdSG6gbAOwcEid1GavJ4FTD0ZuHVTferdvJwKal77RlMtFJGBzL5GjtL0ie8ZJztsGjUWi8DWrnw1pDdDRGS005Hk0ahql"
|
||||
# STRIPE_WEBHOOK_SECRET="whsec_dc9b9084fc764c806c8c5c06dd91de1ee809e9c8deab6d56e8e3ef2fc9c30c67"
|
||||
|
||||
FRONTEND_URL="http://127.0.0.1:5173"
|
||||
RAZERPAY_KEY_ID="rzp_test_smzQmWoS64S2W9"
|
||||
RAZERPAY_SECRET_KEY="cSn6MgA4xSEaZBpPp4zpDA3C"
|
||||
RAZERPAY_KEY_ID="rzp_test_2rg1Bq3Ki8xw9e"
|
||||
RAZERPAY_SECRET_KEY="WFhHbXL7AlLIuull9kKjYiNA"
|
||||
FRONTEND_URL="https://smellika.com"
|
||||
|
||||
|
||||
|
4
app.js
4
app.js
@ -171,7 +171,7 @@ import CouponRoute from "./resources/Affiliate&Coupon/Coupon/CouponRoute.js";
|
||||
// import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js";
|
||||
//support Ticket
|
||||
import SupportRouter from "./resources/Supports/supportRoute.js";
|
||||
import RegisterEmail from "./resources/EmailCMS/RegisterEmail/RegisterEmailRoutes.js";
|
||||
// Point of Sale
|
||||
app.use("/api/v1/", user);
|
||||
|
||||
//Product
|
||||
@ -239,6 +239,6 @@ app.use("/api/panel", PanelRoute);
|
||||
//Support
|
||||
|
||||
// Email CMS
|
||||
app.use("/api", RegisterEmail);
|
||||
// app.use("/api", RegisterEmail);
|
||||
app.use("/api", SupportRouter);
|
||||
export default app;
|
||||
|
@ -110,7 +110,6 @@ export const isFranchiAuthenticated = async (req, res, next) => {
|
||||
// };
|
||||
|
||||
export const authorizeRoles = (...roles) => {
|
||||
console.log("this is the roles ", roles);
|
||||
//pass admin
|
||||
return (req, res, next) => {
|
||||
if (!roles.includes(req.user.role)) {
|
||||
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -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",
|
||||
|
225
resources/Orders/PosCheckoutController.js
Normal file
225
resources/Orders/PosCheckoutController.js
Normal file
@ -0,0 +1,225 @@
|
||||
import { shippingAddress } from "../ShippingAddresses/ShippingAddressModel.js";
|
||||
import { Order } from "./orderModel.js";
|
||||
|
||||
import sendEmail from "../../Utils/sendEmail.js";
|
||||
//generate unique order id
|
||||
const generateUniqueOrderId = async () => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
// Find the latest order to get the last serial number
|
||||
const latestOrder = await Order.findOne({}, {}, { sort: { orderID: -1 } });
|
||||
let serialNumber = 1;
|
||||
|
||||
if (latestOrder) {
|
||||
const lastYear = parseInt(latestOrder.orderID.substring(0, 4), 10);
|
||||
if (lastYear === currentYear) {
|
||||
// If the last order was in the current year, increment the serial number
|
||||
serialNumber = parseInt(latestOrder.orderID.substring(4), 10) + 1;
|
||||
}
|
||||
}
|
||||
// Pad the serial number with zeros and concatenate with the current year
|
||||
const paddedSerialNumber = serialNumber.toString().padStart(7, "0");
|
||||
const orderId = `${currentYear}${paddedSerialNumber}`;
|
||||
return orderId;
|
||||
};
|
||||
|
||||
export const poscreateOrderCheckout = async (req, res) => {
|
||||
try {
|
||||
const { userr, address, cart, subtotal, orderType } = req.body;
|
||||
|
||||
// Perform validation
|
||||
if (cart.length < 1)
|
||||
return res.status(400).json({ message: "Cart is empty!" });
|
||||
if (!address)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "Please select a shipping address!" });
|
||||
if (!subtotal)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "Please provide the product subtotal!" });
|
||||
if (!userr) return res.status(400).json({ message: "User is not defined" });
|
||||
|
||||
// Retrieve shipping address from database
|
||||
let addss = await shippingAddress.findById(address);
|
||||
|
||||
let shipping = {
|
||||
first_Name: addss.first_Name,
|
||||
last_Name: addss?.last_Name,
|
||||
phone_Number: addss?.phone_Number,
|
||||
street: addss?.street,
|
||||
city: addss?.city,
|
||||
state: addss?.state,
|
||||
postalCode: addss?.postalCode,
|
||||
country: addss?.country,
|
||||
company_name: addss?.company_name,
|
||||
gst_number: addss?.gst_number,
|
||||
addressId: address,
|
||||
};
|
||||
|
||||
// Construct order items array
|
||||
const orderItems = cart.map((item) => ({
|
||||
product: item.product._id,
|
||||
name: item.product.name,
|
||||
variant_Name: item.variant.variant_Name,
|
||||
price: Number(item.variant.price),
|
||||
total_price: item.quantity * Number(item.variant.price),
|
||||
image: item.product.image,
|
||||
quantity: item.quantity,
|
||||
gst_amount: Number(
|
||||
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||
)?.toFixed(3),
|
||||
total_gst_amount: Number(
|
||||
Number(item.quantity) *
|
||||
Number((Number(item.variant.price) * item.variant.gst_Id?.tax) / 100)
|
||||
)?.toFixed(3),
|
||||
gst_rate: item.variant.gst_Id?.tax,
|
||||
tax_Name: item.variant?.gst_Id?.name,
|
||||
product_Subtotal: Number(
|
||||
Number(item.quantity * Number(item.variant.price)) +
|
||||
Number(
|
||||
Number(item.quantity) *
|
||||
Number(
|
||||
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||
)
|
||||
)
|
||||
).toFixed(3),
|
||||
}));
|
||||
|
||||
// Generate a unique order ID
|
||||
const Id = await generateUniqueOrderId();
|
||||
|
||||
// Create the order document
|
||||
const order = await Order.create({
|
||||
orderID: Id,
|
||||
total_amount: subtotal,
|
||||
orderItems,
|
||||
shippingInfo: shipping,
|
||||
user: userr,
|
||||
orderType,
|
||||
paymentMode: "cod",
|
||||
payment_status: "success",
|
||||
isPaid: true,
|
||||
paidAt: new Date().toISOString(),
|
||||
});
|
||||
// console.log(order);
|
||||
// Find the user associated with the order
|
||||
const orderWithUser = await Order.findById(order._id).populate("user");
|
||||
|
||||
if (!orderWithUser) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ success: false, message: "Order not found" });
|
||||
}
|
||||
|
||||
const user = orderWithUser.user;
|
||||
const userEmail = user.email;
|
||||
|
||||
// Send email after order creation
|
||||
await sendEmail({
|
||||
to: userEmail,
|
||||
from: `${process.env.SEND_EMAIL_FROM}`,
|
||||
subject: `Your Order #${order?.orderID} Confirmation`,
|
||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
order?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
|
||||
<p style="color: #555; font-size: 15px;">Great news! Your order #${
|
||||
order?.orderID
|
||||
} has been confirmed. Here are the details</p>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Shipping Address : ${
|
||||
order?.shippingInfo?.first_Name
|
||||
} ${order?.shippingInfo?.last_Name} , ${order?.shippingInfo?.street} ${
|
||||
order?.shippingInfo?.city
|
||||
} ${order?.shippingInfo?.state} ${order?.shippingInfo?.country}, PIN-${
|
||||
order?.shippingInfo?.postalCode
|
||||
}, Phone Number: ${order?.shippingInfo?.phone_Number}
|
||||
${
|
||||
order?.shippingInfo?.company_name
|
||||
? ",Company Name :" + order?.shippingInfo?.company_name + ""
|
||||
: ""
|
||||
} ${
|
||||
order?.shippingInfo?.gst_number
|
||||
? ", GST_NO:" + order?.shippingInfo?.gst_number
|
||||
: ""
|
||||
}</h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${order?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
|
||||
return res.status(201).json({ success: true, order });
|
||||
} catch (error) {
|
||||
console.error("Error creating order:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ success: false, message: "Internal server error" });
|
||||
}
|
||||
};
|
@ -31,6 +31,8 @@ const generateUniqueOrderId = async () => {
|
||||
|
||||
export const getRzpkey = async (req, res) => {
|
||||
const { name, email } = req.user;
|
||||
// console.log(name);
|
||||
// console.log(email);
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
key: process.env.RAZERPAY_KEY_ID,
|
||||
@ -38,22 +40,36 @@ export const getRzpkey = async (req, res) => {
|
||||
email,
|
||||
});
|
||||
};
|
||||
//point of sale order
|
||||
export const getRazerpayKey = async (req, res) => {
|
||||
try {
|
||||
const { name, email } = req.params;
|
||||
// console.log("name", name, "email", email);
|
||||
if (!name || !email) {
|
||||
throw new Error("Name and email are required parameters");
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
key: process.env.RAZERPAY_KEY_ID,
|
||||
name,
|
||||
email,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error in getRzpKey:", error);
|
||||
res
|
||||
.status(500)
|
||||
.json({
|
||||
success: false,
|
||||
message: error.message || "Internal server error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const checkout = async (req, res) => {
|
||||
// console.log(req.body.subtotal);
|
||||
const options = {
|
||||
amount: Number(req.body.subtotal * 100),
|
||||
currency: "INR",
|
||||
};
|
||||
const order = await instance.orders.create(options);
|
||||
// id: "order_Ns423uPG0r36Dk";
|
||||
|
||||
//save order in database
|
||||
|
||||
if (order?.id) {
|
||||
const { email } = req.user;
|
||||
if (!email)
|
||||
return res.status(400).send({ message: "Please enter the email" });
|
||||
const { address, cart, subtotal } = req.body;
|
||||
try {
|
||||
const { userr,address, cart, subtotal,orderType } = req.body;
|
||||
// console.log(req.body.cart[0].product);
|
||||
// console.log(req.body.cart[0].variant);
|
||||
if (cart.length < 1)
|
||||
return res.status(400).json({ message: "cart is empty!" });
|
||||
if (!address)
|
||||
@ -64,63 +80,103 @@ export const checkout = async (req, res) => {
|
||||
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,
|
||||
last_Name: addss.last_Name,
|
||||
phone_Number: addss.phone_Number,
|
||||
street: addss.street,
|
||||
city: addss.city,
|
||||
state: addss.state,
|
||||
postalCode: addss?.postalCode,
|
||||
country: addss.country,
|
||||
addressId: address,
|
||||
const options = {
|
||||
amount: Number(req.body.subtotal * 100),
|
||||
currency: "INR",
|
||||
};
|
||||
// console.log("cart", cart[0]?.product?.gst);
|
||||
const orderItems = await cart.map((item) => ({
|
||||
product: item.product._id,
|
||||
name: item.product.name,
|
||||
price: item.product.price,
|
||||
total_Amount: item.product.total_amount,
|
||||
// Determine the user ID
|
||||
let User;
|
||||
if (userr) {
|
||||
User = userr; // Use provided user ID
|
||||
} else {
|
||||
User = req.user._id; // Use authenticated user ID
|
||||
}
|
||||
// console.log(User);
|
||||
const order = await instance.orders.create(options);
|
||||
// console.log(order);
|
||||
//save order in database
|
||||
if (order?.id) {
|
||||
// const { email } = req.user;
|
||||
// if (!email)
|
||||
// return res.status(400).send({ message: "Please enter the email" });
|
||||
let addss = await shippingAddress.findById(address);
|
||||
|
||||
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,
|
||||
}));
|
||||
let shipping = {
|
||||
first_Name: addss.first_Name,
|
||||
last_Name: addss?.last_Name,
|
||||
phone_Number: addss?.phone_Number,
|
||||
street: addss?.street,
|
||||
city: addss?.city,
|
||||
state: addss?.state,
|
||||
postalCode: addss?.postalCode,
|
||||
country: addss?.country,
|
||||
company_name: addss?.company_name,
|
||||
gst_number: addss?.gst_number,
|
||||
addressId: address,
|
||||
};
|
||||
// console.log("cart", cart[0]?.product?.gst);
|
||||
const orderItems = await cart.map((item) => ({
|
||||
product: item.product._id,
|
||||
name: item.product.name,
|
||||
variant_Name: item.variant.variant_Name,
|
||||
price: Number(item.variant.price),
|
||||
total_price: item.quantity * Number(item.variant.price),
|
||||
|
||||
// console.log("line", lineItems[0]);
|
||||
const Id = await generateUniqueOrderId();
|
||||
const orders = await Order.create({
|
||||
orderID: Id,
|
||||
total_amount: subtotal,
|
||||
orderItems,
|
||||
shippingInfo: shipping,
|
||||
user: req.user._id,
|
||||
razorpay_order_id: order?.id,
|
||||
image: item.product.image,
|
||||
quantity: item.quantity,
|
||||
gst_amount: Number(
|
||||
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||
)?.toFixed(3),
|
||||
total_gst_amount: Number(
|
||||
Number(item.quantity) *
|
||||
Number(
|
||||
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||
)
|
||||
)?.toFixed(3),
|
||||
gst_rate: item.variant.gst_Id?.tax,
|
||||
tax_Name: item.variant?.gst_Id?.name,
|
||||
product_Subtotal: Number(
|
||||
Number(item.quantity * Number(item.variant.price)) +
|
||||
Number(
|
||||
Number(item.quantity) *
|
||||
Number(
|
||||
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||
)
|
||||
)
|
||||
).toFixed(3),
|
||||
}));
|
||||
|
||||
// console.log("Order", orderItems[0]);
|
||||
const Id = await generateUniqueOrderId();
|
||||
const orders = await Order.create({
|
||||
orderID: Id,
|
||||
total_amount: subtotal,
|
||||
orderItems,
|
||||
shippingInfo: shipping,
|
||||
user: User,
|
||||
razorpay_order_id: order?.id,
|
||||
orderType,
|
||||
});
|
||||
} else {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Failled to order Create",
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
order,
|
||||
});
|
||||
} else {
|
||||
res.status(400).json({
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Failled to order Create",
|
||||
message: error?.description
|
||||
? "Razorpay" + error?.description
|
||||
: "Something went wrong!",
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
order,
|
||||
});
|
||||
};
|
||||
|
||||
export const paymentVerification = async (req, res) => {
|
||||
@ -180,7 +236,16 @@ export const paymentVerification = async (req, res) => {
|
||||
findSameOrder?.shippingInfo?.state
|
||||
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
||||
findSameOrder?.shippingInfo?.postalCode
|
||||
}, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}</h4>
|
||||
}, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}
|
||||
${
|
||||
findSameOrder?.shippingInfo?.company_name
|
||||
? ",Company Name :" + findSameOrder?.shippingInfo?.company_name + ""
|
||||
: ""
|
||||
} ${
|
||||
findSameOrder?.shippingInfo?.gst_number
|
||||
? ", GST_NO:" + findSameOrder?.shippingInfo?.gst_number
|
||||
: ""
|
||||
}</h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
@ -188,6 +253,8 @@ export const paymentVerification = async (req, res) => {
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
@ -210,6 +277,9 @@ export const paymentVerification = async (req, res) => {
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
@ -226,7 +296,7 @@ export const paymentVerification = async (req, res) => {
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.product_Subtotal
|
||||
product?.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
@ -234,7 +304,7 @@ export const paymentVerification = async (req, res) => {
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
findSameOrder?.total_amount
|
||||
}</td>
|
||||
@ -269,6 +339,167 @@ export const paymentVerification = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// point of sale payment varification
|
||||
export const pospaymentVerification = async (req, res) => {
|
||||
const { razorpay_order_id, razorpay_payment_id, razorpay_signature } =
|
||||
req.body;
|
||||
|
||||
const body = razorpay_order_id + "|" + razorpay_payment_id;
|
||||
|
||||
const expectedSignature = crypto
|
||||
.createHmac("sha256", process.env.RAZERPAY_SECRET_KEY)
|
||||
.update(body.toString())
|
||||
.digest("hex");
|
||||
|
||||
const isAuthentic = expectedSignature === razorpay_signature;
|
||||
|
||||
if (isAuthentic) {
|
||||
// Database comes here
|
||||
let findSameOrder = await Order.findOne({
|
||||
razorpay_order_id: razorpay_order_id,
|
||||
}).populate({
|
||||
path: "user",
|
||||
select: "name email -_id",
|
||||
});
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
if (findSameOrder) {
|
||||
(findSameOrder.razorpay_payment_id = razorpay_payment_id), // await Payment.create({
|
||||
(findSameOrder.isPaid = true),
|
||||
(findSameOrder.paidAt = Date.now()),
|
||||
(findSameOrder.razorpay_signature = razorpay_signature);
|
||||
// await Payment.create({
|
||||
findSameOrder.payment_status = "success";
|
||||
|
||||
findSameOrder.orderStatus = "new";
|
||||
await findSameOrder.save();
|
||||
}
|
||||
//send email to customer
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
await sendEmail({
|
||||
to: `${findSameOrder?.user?.email}`, // Change to your recipient
|
||||
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
|
||||
subject: `Your Order #${findSameOrder?.orderID} Confirmation`,
|
||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
findSameOrder?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
|
||||
<p style="color: #555; font-size: 15px;">Great news! Your order #${
|
||||
findSameOrder?.orderID
|
||||
} has been confirmed. Here are the details</p>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">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}
|
||||
${
|
||||
findSameOrder?.shippingInfo?.company_name
|
||||
? ",Company Name :" + findSameOrder?.shippingInfo?.company_name + ""
|
||||
: ""
|
||||
} ${
|
||||
findSameOrder?.shippingInfo?.gst_number
|
||||
? ", GST_NO:" + findSameOrder?.shippingInfo?.gst_number
|
||||
: ""
|
||||
}</h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${findSameOrder?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
findSameOrder?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
|
||||
// // findSameOrder.razorpay_payment_id=razorpay_payment_id,// await Payment.create({
|
||||
// findOrder.paidAt = new Date(event.data.object.created * 1000);
|
||||
// findOrder.isPaid = true;
|
||||
|
||||
// razorpay_signature: { type: String },
|
||||
// razorpay_order_id,
|
||||
// razorpay_payment_id,
|
||||
// razorpay_signature,
|
||||
// });
|
||||
|
||||
res.redirect(`https://admin.smellika.com/#/pos`);
|
||||
// res.redirect(`http://localhost:3000/#/pos`);
|
||||
} else {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const handlePayment = async (req, res) => {
|
||||
try {
|
||||
const { email } = req.user;
|
||||
|
@ -176,14 +176,12 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
@ -199,6 +197,9 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
@ -224,7 +225,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
@ -267,6 +268,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
@ -288,6 +290,9 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
@ -313,7 +318,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
@ -383,6 +388,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
@ -404,6 +410,9 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
@ -429,7 +438,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
@ -470,8 +479,8 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
@ -491,6 +500,9 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product?.variant_Name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
@ -516,7 +528,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
|
@ -50,6 +50,12 @@ const orderSchema = new mongoose.Schema(
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
company_name: {
|
||||
type: String,
|
||||
},
|
||||
gst_number: {
|
||||
type: String,
|
||||
},
|
||||
addressId: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "ShippingAddress",
|
||||
@ -62,11 +68,15 @@ const orderSchema = new mongoose.Schema(
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
variant_Name: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
total_Amount: {
|
||||
total_price: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
@ -85,6 +95,10 @@ const orderSchema = new mongoose.Schema(
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
total_gst_amount: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
gst_rate: {
|
||||
type: Number,
|
||||
default: "",
|
||||
@ -110,7 +124,11 @@ const orderSchema = new mongoose.Schema(
|
||||
enum: ["online", "cod"],
|
||||
default: "online",
|
||||
},
|
||||
|
||||
orderType: {
|
||||
type: String,
|
||||
enum: ["WebSite", "PointOfSale"],
|
||||
default: "WebSite",
|
||||
},
|
||||
payment_status: {
|
||||
type: String,
|
||||
enum: ["pending", "success", "failed"],
|
||||
|
@ -22,12 +22,17 @@ app.use(bodyParser.raw({ type: "application/json" }));
|
||||
import { handlePayment, webhook } from "./StripeCheckOutController.js";
|
||||
import {
|
||||
checkout,
|
||||
getRazerpayKey,
|
||||
getRzpkey,
|
||||
paymentVerification,
|
||||
pospaymentVerification,
|
||||
} from "./RazerPayCheckoutController.js";
|
||||
import { poscreateOrderCheckout } from "./PosCheckoutController.js";
|
||||
const router = express.Router();
|
||||
//checkout Routes-------------------------//
|
||||
router.route("/checkout/").post(isAuthenticatedUser, createOrderCheckout);
|
||||
//checkout Routes-------------------------//
|
||||
router.route("/pos-checkout/").post(isAuthenticatedUser, poscreateOrderCheckout);
|
||||
router.route("/clientid/get/").get(isAuthenticatedUser, getClientId);
|
||||
router.route("/:orderID/capture/payment").post(captureOrderPayment);
|
||||
// ---------------------------------------------------
|
||||
@ -68,10 +73,11 @@ router
|
||||
);
|
||||
|
||||
//RAZERPAY checkout
|
||||
router.route("/getRzpKey/:name/:email").get(isAuthenticatedUser, getRazerpayKey);
|
||||
router.route("/getRzpKey/").get(isAuthenticatedUser, getRzpkey);
|
||||
router.route("/Rzpcheckout/").post(isAuthenticatedUser, checkout);
|
||||
router.route("/paymentverification").post(paymentVerification);
|
||||
|
||||
router.route("/pos-paymentverification").post(pospaymentVerification);
|
||||
// router.route("/product/getAll/").get(getAllProduct)
|
||||
|
||||
export default router;
|
||||
|
@ -124,6 +124,8 @@ export const getAllProductAdmin = async (req, res) => {
|
||||
$options: "i",
|
||||
};
|
||||
if (req.query?.category) obj.category = req.query.category;
|
||||
if (req.query?.FeatureProduct)
|
||||
obj.featured_Product = req.query.FeatureProduct;
|
||||
const total = await Product.countDocuments(obj);
|
||||
const product = await Product.find(obj)
|
||||
.populate({
|
||||
@ -134,6 +136,7 @@ export const getAllProductAdmin = async (req, res) => {
|
||||
.skip(PAGE_SIZE * page)
|
||||
// .sort("name")
|
||||
.sort({
|
||||
featured_Product: -1,
|
||||
createdAt: -1,
|
||||
})
|
||||
.exec();
|
||||
@ -166,6 +169,8 @@ export const getAllProductUser = async (req, res) => {
|
||||
$options: "i",
|
||||
};
|
||||
if (req.query?.category) obj.category = req.query.category;
|
||||
if (req.query?.FeatureProduct)
|
||||
obj.featured_Product = req.query.FeatureProduct;
|
||||
obj.product_Status = "Active";
|
||||
const total = await Product.countDocuments(obj);
|
||||
const product = await Product.find(obj)
|
||||
@ -177,6 +182,7 @@ export const getAllProductUser = async (req, res) => {
|
||||
.skip(PAGE_SIZE * page)
|
||||
// .sort("name")
|
||||
.sort({
|
||||
featured_Product: -1,
|
||||
createdAt: -1,
|
||||
})
|
||||
.exec();
|
||||
@ -230,6 +236,49 @@ export const ChangeProductStatus = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
//Change Product status
|
||||
export const ChangeFeatueProductStatus = async (req, res) => {
|
||||
try {
|
||||
const data = await Product.findById(req.params.id);
|
||||
if (data) {
|
||||
if (data?.featured_Product === false) {
|
||||
const totalFeatueProduct = await Product.countDocuments({
|
||||
featured_Product: true,
|
||||
});
|
||||
if (totalFeatueProduct > 2) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
msg: "Maximum 3 Featue Product can be..",
|
||||
});
|
||||
}
|
||||
let product = await Product.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
{ featured_Product: true },
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Changed status as Featue Product",
|
||||
});
|
||||
} else {
|
||||
let product = await Product.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
{ featured_Product: false },
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: "Changed status as not Featue Product",
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: error.message ? error.message : "Something went wrong!",
|
||||
});
|
||||
}
|
||||
};
|
||||
//get One Product
|
||||
export const getOneProduct = async (req, res) => {
|
||||
try {
|
||||
@ -503,14 +552,14 @@ export const deleteProduct = async (req, res) => {
|
||||
if (!req.params.id) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
msg: "Please Provide Product ID!",
|
||||
message: "Please Provide Product ID!",
|
||||
});
|
||||
}
|
||||
const getProduct = await Product.findById(req.params.id);
|
||||
if (!getProduct) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
msg: "Product not Found!",
|
||||
message: "Product not Found!",
|
||||
});
|
||||
}
|
||||
// Deleting Images From Cloudinary
|
||||
@ -528,7 +577,7 @@ export const deleteProduct = async (req, res) => {
|
||||
await product.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Product Deleted Successfully!!",
|
||||
message: "Product Deleted Successfully!!",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
|
@ -38,6 +38,10 @@ const productSchema = new Schema(
|
||||
special_instructions: {
|
||||
type: String,
|
||||
},
|
||||
featured_Product: {
|
||||
type: Boolean,
|
||||
default: false, // Initially, products are not featured
|
||||
},
|
||||
variants: [
|
||||
{
|
||||
variant_Name: { type: String, default: "" },
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
getAllProductUser,
|
||||
getAllProductsDevicesFirst,
|
||||
ChangeProductStatus,
|
||||
ChangeFeatueProductStatus,
|
||||
} from "./ProductController.js";
|
||||
const router = express.Router();
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
@ -30,6 +31,10 @@ router
|
||||
|
||||
//change Product status
|
||||
router.route("/product/admin/status/:id").patch(ChangeProductStatus);
|
||||
router
|
||||
.route("/product/admin/feature_product/status/:id")
|
||||
.patch(ChangeFeatueProductStatus);
|
||||
|
||||
//get all product user
|
||||
router.route("/product/getAll/user/").get(getAllProductUser);
|
||||
router
|
||||
|
@ -40,11 +40,16 @@ const shippingAddressSchema = new mongoose.Schema(
|
||||
},
|
||||
company_name: {
|
||||
type: String,
|
||||
maxLength: [70, "name cannot exceed 70 characters"],
|
||||
},
|
||||
gst_number: {
|
||||
type: Number,
|
||||
maxLength: [15, "name cannot exceed 15 characters"],
|
||||
type: String,
|
||||
validate: {
|
||||
validator: function (v) {
|
||||
// Regular expression for Indian GST number validation
|
||||
return /^(\d{2}[A-Z]{5}\d{4}[A-Z]{1}\d[Z]{1}[A-Z\d]{1})$/.test(v);
|
||||
},
|
||||
message: (props) => `${props.value} is not a valid Indian GST number!`,
|
||||
},
|
||||
},
|
||||
default: {
|
||||
type: Boolean,
|
||||
|
Loading…
Reference in New Issue
Block a user