Merge branch 'main' of https://git.cnapp.co.in/gitadmin/api
This commit is contained in:
commit
c279b8d7de
@ -86,16 +86,18 @@ export const addInventory = async (req, res) => {
|
|||||||
export const getDistributors = async (req, res) => {
|
export const getDistributors = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { type } = req.params;
|
const { type } = req.params;
|
||||||
|
// console.log(req.params);
|
||||||
if (!["PrincipalDistributor", "RetailDistributor"].includes(type)) {
|
if (!["PrincipalDistributor", "RetailDistributor"].includes(type)) {
|
||||||
return res.status(400).json({ message: "Invalid distributor type" });
|
return res.status(400).json({ message: "Invalid distributor type" });
|
||||||
}
|
}
|
||||||
|
// console.log(req.userType);
|
||||||
let filter = { role: "principal-Distributor" };
|
let filter = { role: "principal-Distributor" };
|
||||||
let query = {};
|
let query = {};
|
||||||
// Check the user type and adjust the filter accordingly
|
// Check the user type and adjust the filter accordingly
|
||||||
|
// console.log(req.user);
|
||||||
if (req.userType === "SalesCoOrdinator") {
|
if (req.userType === "SalesCoOrdinator") {
|
||||||
// If userType is "SalesCoOrdinator", filter by req.user.mappedBy
|
// If userType is "SalesCoOrdinator", filter by req.user.mappedBy
|
||||||
filter.mappedby = req.user.mappedby;
|
filter.mappedbySC = req.user._id;
|
||||||
query.mappedSC = req.user._id;
|
query.mappedSC = req.user._id;
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, filter by req.user._id
|
// Otherwise, filter by req.user._id
|
||||||
@ -195,7 +197,9 @@ export const getAllInventories = async (req, res) => {
|
|||||||
addedForData.shippingAddress?.tradeName?.toLowerCase() || "";
|
addedForData.shippingAddress?.tradeName?.toLowerCase() || "";
|
||||||
}
|
}
|
||||||
} else if (inventory.addedFor === "RetailDistributor") {
|
} else if (inventory.addedFor === "RetailDistributor") {
|
||||||
addedForData = await RetailDistributor.findById(inventory.addedForId).populate("kyc");
|
addedForData = await RetailDistributor.findById(
|
||||||
|
inventory.addedForId
|
||||||
|
).populate("kyc");
|
||||||
tradeName = addedForData?.kyc?.trade_name?.toLowerCase() || "";
|
tradeName = addedForData?.kyc?.trade_name?.toLowerCase() || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +277,9 @@ export const getSingleInventory = async (req, res) => {
|
|||||||
shippingAddress,
|
shippingAddress,
|
||||||
};
|
};
|
||||||
} else if (inventory.addedFor === "RetailDistributor") {
|
} else if (inventory.addedFor === "RetailDistributor") {
|
||||||
addedForData = await RetailDistributor.findById(inventory.addedForId).populate("kyc");
|
addedForData = await RetailDistributor.findById(
|
||||||
|
inventory.addedForId
|
||||||
|
).populate("kyc");
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
@ -89,8 +89,9 @@ export const uploadOpeningInventory = async (req, res) => {
|
|||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (!item.SKU) missingFields.add("SKU");
|
if (!item.SKU) missingFields.add("SKU");
|
||||||
if (!item.productName) missingFields.add("Product Name");
|
if (!item.productName) missingFields.add("Product Name");
|
||||||
if (!item.openingInventory) missingFields.add("Opening Inventory (Qty)");
|
if (item.openingInventory === null || item.openingInventory === undefined) {
|
||||||
|
missingFields.add("Opening Inventory (Qty)");
|
||||||
|
}
|
||||||
// Combine all errors into a single message
|
// Combine all errors into a single message
|
||||||
let errorMessage = "";
|
let errorMessage = "";
|
||||||
if (missingFields.size > 0) {
|
if (missingFields.size > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user