error handling for not Assoicated Rd
This commit is contained in:
parent
4972241bf7
commit
60dd5e0d82
@ -22,6 +22,7 @@ export const createOrderRD = async (req, res) => {
|
||||
} = req.body;
|
||||
|
||||
const rdId = req.user._id;
|
||||
console.log(rdId);
|
||||
// Fetch the Retail Distributor (RD) to find the associated Principal Distributor (PD)
|
||||
const rd = await RetailDistributor.findById(rdId).populate(
|
||||
"principal_distributer"
|
||||
@ -31,6 +32,11 @@ export const createOrderRD = async (req, res) => {
|
||||
return res.status(404).json({ message: "Retail Distributor not found" });
|
||||
}
|
||||
|
||||
if (!rd.principal_distributer) {
|
||||
return res.status(422).json({
|
||||
msg: "You are not assoicated with any Pd please contact support team",
|
||||
});
|
||||
}
|
||||
const pdId = rd.principal_distributer._id;
|
||||
|
||||
if (pdId) {
|
||||
@ -80,6 +86,7 @@ export const createOrderRD = async (req, res) => {
|
||||
.status(201)
|
||||
.json({ message: "Order placed successfully", order: newOrder });
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
res.status(500).json({ message: "Server error", error });
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user