getting pd/rd for sc and tm fixed
This commit is contained in:
parent
6df7ab6eab
commit
2ade217606
@ -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({
|
||||||
|
Loading…
Reference in New Issue
Block a user