diff --git a/resources/KYC/KycController.js b/resources/KYC/KycController.js index 545dcf9..fe17c63 100644 --- a/resources/KYC/KycController.js +++ b/resources/KYC/KycController.js @@ -134,12 +134,26 @@ export const createretaildistributor = async (req, res) => { return res.status(400).json({ message: "No files were uploaded." }); } - const { selfieEntranceImg, panImg, aadharImg, gstImg, pesticideLicenseImg } = req.files; + const { + selfieEntranceImg, + panImg, + aadharImg, + gstImg, + pesticideLicenseImg, + } = req.files; // console.log(req.files); const fertilizerLicenseImg = req.files.fertilizerLicenseImg || null; - if (!panImg || !aadharImg || !gstImg || !selfieEntranceImg || !pesticideLicenseImg) { - return res.status(400).json({ message: "Please upload all required images." }); + if ( + !panImg || + !aadharImg || + !gstImg || + !selfieEntranceImg || + !pesticideLicenseImg + ) { + return res + .status(400) + .json({ message: "Please upload all required images." }); } // Upload images to Cloudinary @@ -157,9 +171,18 @@ export const createretaildistributor = async (req, res) => { const pan_img = await uploadImage(panImg, "KYC/pan"); const aadhar_img = await uploadImage(aadharImg, "KYC/aadhar"); const gst_img = await uploadImage(gstImg, "KYC/gst"); - const pesticide_license_img = await uploadImage(pesticideLicenseImg, "KYC/pesticide_license"); - const fertilizer_license_img= await uploadImage(fertilizerLicenseImg, "KYC/fertilizer_license"); - const selfie_entrance_img = await uploadImage(selfieEntranceImg, "KYC/selfie_entrance"); + const pesticide_license_img = await uploadImage( + pesticideLicenseImg, + "KYC/pesticide_license" + ); + const fertilizer_license_img = await uploadImage( + fertilizerLicenseImg, + "KYC/fertilizer_license" + ); + const selfie_entrance_img = await uploadImage( + selfieEntranceImg, + "KYC/selfie_entrance" + ); // Create KYC document const kycData = { @@ -186,7 +209,9 @@ export const createretaildistributor = async (req, res) => { const kyc = await KYC.create(kycData); if (kyc) { - return res.status(201).json({ success: true, kyc, message: "KYC created" }); + return res + .status(201) + .json({ success: true, kyc, message: "KYC created" }); } } catch (error) { res.status(500).json({ @@ -355,19 +380,18 @@ export const getAllPrincipalDistributers = async (req, res) => { try { // Define the filter for the query let filter = { role: "principal-Distributor" }; - // Check the user type and adjust the filter accordingly if (req.userType === "SalesCoOrdinator") { // If userType is "SalesCoOrdinator", filter by req.user.mappedBy - filter.mappedBy = req.user.mappedBy; + filter.mappedby = req.user.mappedby; } else { // Otherwise, filter by req.user._id - filter.mappedBy = req.user._id; + filter.mappedby = req.user._id; } - + console.log(filter); // Fetch the principal distributors based on the filter const principalDistributers = await User.find(filter); - +console.log(principalDistributers); // Send the fetched data as a response if (principalDistributers.length > 0) { res.status(200).json(principalDistributers); @@ -380,7 +404,6 @@ export const getAllPrincipalDistributers = async (req, res) => { } }; - // Fcm token storing export const saveFCMTokenForSC = async (req, res) => { const { fcmToken } = req.body; @@ -440,15 +463,15 @@ export const saveFCMTokenForTM = async (req, res) => { export const getAllKycApprovedbytmid = async (req, res) => { try { const { id } = req.params; // Extracting `addedBy` ID from req.params - const { tradename, page = 1, show = 10 } = req.query; - - const query = { status: "approved", mappedTM: id }; + const { tradename, page = 1, show = 10 } = req.query; + + const query = { status: "approved", mappedTM: id }; if (tradename) { - query.trade_name = new RegExp(tradename, "i"); + query.trade_name = new RegExp(tradename, "i"); } - const skip = (page - 1) * show; + const skip = (page - 1) * show; const retaildistributor = await KYC.find(query) .sort({ createdAt: -1 }) @@ -458,13 +481,13 @@ export const getAllKycApprovedbytmid = async (req, res) => { .populate("addedBy") .skip(skip) .limit(parseInt(show)); -const total_data = await KYC.countDocuments(query); + const total_data = await KYC.countDocuments(query); // Send the fetched data as a response res.status(200).json({ success: true, total_data: total_data, total_pages: Math.ceil(total_data / page), - retaildistributor + retaildistributor, }); } catch (error) { // Handle any errors that occur during the fetch operation @@ -512,4 +535,4 @@ export const updateKYCMapped = async (req, res) => { error: error.message, }); } -}; \ No newline at end of file +};