From 60dd5e0d82e9fbfe689ca659835cb474f690c82c Mon Sep 17 00:00:00 2001 From: ROSHAN GARG Date: Fri, 22 Nov 2024 13:43:42 +0530 Subject: [PATCH] error handling for not Assoicated Rd --- resources/RD_Ordes/rdOrderController.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/RD_Ordes/rdOrderController.js b/resources/RD_Ordes/rdOrderController.js index 3151570..379a43d 100644 --- a/resources/RD_Ordes/rdOrderController.js +++ b/resources/RD_Ordes/rdOrderController.js @@ -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 }); } };