Merge branch 'master' of http://128.199.30.231/possibillion/smellika-api
This commit is contained in:
commit
83a782f735
@ -62,15 +62,18 @@ export const checkout = async (req, res) => {
|
|||||||
if (!email)
|
if (!email)
|
||||||
return res.status(400).send({ message: "Please enter the email" });
|
return res.status(400).send({ message: "Please enter the email" });
|
||||||
let addss = await shippingAddress.findById(address);
|
let addss = await shippingAddress.findById(address);
|
||||||
|
|
||||||
let shipping = {
|
let shipping = {
|
||||||
first_Name: addss.first_Name,
|
first_Name: addss.first_Name,
|
||||||
last_Name: addss.last_Name,
|
last_Name: addss?.last_Name,
|
||||||
phone_Number: addss.phone_Number,
|
phone_Number: addss?.phone_Number,
|
||||||
street: addss.street,
|
street: addss?.street,
|
||||||
city: addss.city,
|
city: addss?.city,
|
||||||
state: addss.state,
|
state: addss?.state,
|
||||||
postalCode: addss?.postalCode,
|
postalCode: addss?.postalCode,
|
||||||
country: addss.country,
|
country: addss?.country,
|
||||||
|
company_name: addss?.company_name,
|
||||||
|
gst_number: addss?.gst_number,
|
||||||
addressId: address,
|
addressId: address,
|
||||||
};
|
};
|
||||||
// console.log("cart", cart[0]?.product?.gst);
|
// console.log("cart", cart[0]?.product?.gst);
|
||||||
@ -194,7 +197,16 @@ export const paymentVerification = async (req, res) => {
|
|||||||
findSameOrder?.shippingInfo?.state
|
findSameOrder?.shippingInfo?.state
|
||||||
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
||||||
findSameOrder?.shippingInfo?.postalCode
|
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>
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||||
<table style="border-collapse: collapse; width: 100%;">
|
<table style="border-collapse: collapse; width: 100%;">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -50,6 +50,12 @@ const orderSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
company_name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
gst_number: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
addressId: {
|
addressId: {
|
||||||
type: mongoose.Schema.ObjectId,
|
type: mongoose.Schema.ObjectId,
|
||||||
ref: "ShippingAddress",
|
ref: "ShippingAddress",
|
||||||
|
@ -124,6 +124,8 @@ export const getAllProductAdmin = async (req, res) => {
|
|||||||
$options: "i",
|
$options: "i",
|
||||||
};
|
};
|
||||||
if (req.query?.category) obj.category = req.query.category;
|
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 total = await Product.countDocuments(obj);
|
||||||
const product = await Product.find(obj)
|
const product = await Product.find(obj)
|
||||||
.populate({
|
.populate({
|
||||||
@ -134,6 +136,7 @@ export const getAllProductAdmin = async (req, res) => {
|
|||||||
.skip(PAGE_SIZE * page)
|
.skip(PAGE_SIZE * page)
|
||||||
// .sort("name")
|
// .sort("name")
|
||||||
.sort({
|
.sort({
|
||||||
|
featured_Product: -1,
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
@ -166,6 +169,8 @@ export const getAllProductUser = async (req, res) => {
|
|||||||
$options: "i",
|
$options: "i",
|
||||||
};
|
};
|
||||||
if (req.query?.category) obj.category = req.query.category;
|
if (req.query?.category) obj.category = req.query.category;
|
||||||
|
if (req.query?.FeatureProduct)
|
||||||
|
obj.featured_Product = req.query.FeatureProduct;
|
||||||
obj.product_Status = "Active";
|
obj.product_Status = "Active";
|
||||||
const total = await Product.countDocuments(obj);
|
const total = await Product.countDocuments(obj);
|
||||||
const product = await Product.find(obj)
|
const product = await Product.find(obj)
|
||||||
@ -177,6 +182,7 @@ export const getAllProductUser = async (req, res) => {
|
|||||||
.skip(PAGE_SIZE * page)
|
.skip(PAGE_SIZE * page)
|
||||||
// .sort("name")
|
// .sort("name")
|
||||||
.sort({
|
.sort({
|
||||||
|
featured_Product: -1,
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
})
|
})
|
||||||
.exec();
|
.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
|
//get One Product
|
||||||
export const getOneProduct = async (req, res) => {
|
export const getOneProduct = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@ -503,14 +552,14 @@ export const deleteProduct = async (req, res) => {
|
|||||||
if (!req.params.id) {
|
if (!req.params.id) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
msg: "Please Provide Product ID!",
|
message: "Please Provide Product ID!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const getProduct = await Product.findById(req.params.id);
|
const getProduct = await Product.findById(req.params.id);
|
||||||
if (!getProduct) {
|
if (!getProduct) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
success: false,
|
success: false,
|
||||||
msg: "Product not Found!",
|
message: "Product not Found!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Deleting Images From Cloudinary
|
// Deleting Images From Cloudinary
|
||||||
@ -528,7 +577,7 @@ export const deleteProduct = async (req, res) => {
|
|||||||
await product.remove();
|
await product.remove();
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: "Product Deleted Successfully!!",
|
message: "Product Deleted Successfully!!",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
|
@ -38,6 +38,10 @@ const productSchema = new Schema(
|
|||||||
special_instructions: {
|
special_instructions: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
featured_Product: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false, // Initially, products are not featured
|
||||||
|
},
|
||||||
variants: [
|
variants: [
|
||||||
{
|
{
|
||||||
variant_Name: { type: String, default: "" },
|
variant_Name: { type: String, default: "" },
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
getAllProductUser,
|
getAllProductUser,
|
||||||
getAllProductsDevicesFirst,
|
getAllProductsDevicesFirst,
|
||||||
ChangeProductStatus,
|
ChangeProductStatus,
|
||||||
|
ChangeFeatueProductStatus,
|
||||||
} from "./ProductController.js";
|
} from "./ProductController.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
@ -22,6 +23,10 @@ router
|
|||||||
|
|
||||||
//change Product status
|
//change Product status
|
||||||
router.route("/product/admin/status/:id").patch(ChangeProductStatus);
|
router.route("/product/admin/status/:id").patch(ChangeProductStatus);
|
||||||
|
router
|
||||||
|
.route("/product/admin/feature_product/status/:id")
|
||||||
|
.patch(ChangeFeatueProductStatus);
|
||||||
|
|
||||||
//get all product user
|
//get all product user
|
||||||
router.route("/product/getAll/user/").get(getAllProductUser);
|
router.route("/product/getAll/user/").get(getAllProductUser);
|
||||||
router
|
router
|
||||||
|
@ -40,11 +40,16 @@ const shippingAddressSchema = new mongoose.Schema(
|
|||||||
},
|
},
|
||||||
company_name: {
|
company_name: {
|
||||||
type: String,
|
type: String,
|
||||||
maxLength: [70, "name cannot exceed 70 characters"],
|
|
||||||
},
|
},
|
||||||
gst_number: {
|
gst_number: {
|
||||||
type: Number,
|
type: String,
|
||||||
maxLength: [15, "name cannot exceed 15 characters"],
|
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: {
|
default: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
Loading…
Reference in New Issue
Block a user