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) => {
|
||||
try {
|
||||
const { type } = req.params;
|
||||
|
||||
// console.log(req.params);
|
||||
if (!["PrincipalDistributor", "RetailDistributor"].includes(type)) {
|
||||
return res.status(400).json({ message: "Invalid distributor type" });
|
||||
}
|
||||
// console.log(req.userType);
|
||||
let filter = { role: "principal-Distributor" };
|
||||
let query = {};
|
||||
// Check the user type and adjust the filter accordingly
|
||||
// console.log(req.user);
|
||||
if (req.userType === "SalesCoOrdinator") {
|
||||
// If userType is "SalesCoOrdinator", filter by req.user.mappedBy
|
||||
filter.mappedby = req.user.mappedby;
|
||||
filter.mappedbySC = req.user._id;
|
||||
query.mappedSC = req.user._id;
|
||||
} else {
|
||||
// Otherwise, filter by req.user._id
|
||||
@ -195,7 +197,9 @@ export const getAllInventories = async (req, res) => {
|
||||
addedForData.shippingAddress?.tradeName?.toLowerCase() || "";
|
||||
}
|
||||
} 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() || "";
|
||||
}
|
||||
|
||||
@ -273,7 +277,9 @@ export const getSingleInventory = async (req, res) => {
|
||||
shippingAddress,
|
||||
};
|
||||
} 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({
|
||||
|
Loading…
Reference in New Issue
Block a user