From 2c6e38094ca78c0f414825f2375794237913162a Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Fri, 11 Oct 2024 11:42:21 +0530 Subject: [PATCH] fixing --- resources/Inventory/InventoryController.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/resources/Inventory/InventoryController.js b/resources/Inventory/InventoryController.js index 596cb73..aff5e9c 100644 --- a/resources/Inventory/InventoryController.js +++ b/resources/Inventory/InventoryController.js @@ -1,10 +1,8 @@ import { Inventory } from "../Inventory/InventoryModel.js"; import User from "../user/userModel.js"; -import { KYC } from "../KYC/KycModel.js"; import ShippingAddress from "../ShippingAddresses/ShippingAddressModel.js"; import TerritoryManager from "../TerritoryManagers/TerritoryManagerModel.js"; import SalesCoordinator from "../SalesCoOrdinators/SalesCoOrdinatorModel.js"; -import crypto from "crypto"; import RetailDistributor from "../RetailDistributor/RetailDistributorModel.js"; import { RDStock } from "../Stock/RdStockModel.js"; // Add inventory data @@ -125,7 +123,7 @@ export const getDistributors = async (req, res) => { }) ); } else { - // For RetailDistributor, fetch approved KYC documents + // For RetailDistributor distributors = await RetailDistributor.find(query) .populate("kyc") .sort({ createdAt: -1 }); @@ -197,8 +195,8 @@ export const getAllInventories = async (req, res) => { addedForData.shippingAddress?.tradeName?.toLowerCase() || ""; } } else if (inventory.addedFor === "RetailDistributor") { - addedForData = await KYC.findById(inventory.addedForId); - tradeName = addedForData?.trade_name?.toLowerCase() || ""; + addedForData = await RetailDistributor.findById(inventory.addedForId).populate("kyc"); + tradeName = addedForData?.kyc?.trade_name?.toLowerCase() || ""; } return { @@ -275,7 +273,7 @@ export const getSingleInventory = async (req, res) => { shippingAddress, }; } else if (inventory.addedFor === "RetailDistributor") { - addedForData = await KYC.findById(inventory.addedForId); + addedForData = await RetailDistributor.findById(inventory.addedForId).populate("kyc"); } res.status(200).json({