This commit is contained in:
Sibunnayak 2024-04-28 11:21:42 +05:30
commit 83a782f735
6 changed files with 94 additions and 13 deletions

View File

@ -62,15 +62,18 @@ export const checkout = async (req, res) => {
if (!email)
return res.status(400).send({ message: "Please enter the email" });
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,
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,
country: addss?.country,
company_name: addss?.company_name,
gst_number: addss?.gst_number,
addressId: address,
};
// console.log("cart", cart[0]?.product?.gst);
@ -194,7 +197,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>

View File

@ -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",

View File

@ -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({

View File

@ -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: "" },

View File

@ -10,6 +10,7 @@ import {
getAllProductUser,
getAllProductsDevicesFirst,
ChangeProductStatus,
ChangeFeatueProductStatus,
} from "./ProductController.js";
const router = express.Router();
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
@ -22,6 +23,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

View File

@ -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,