mapping RD

This commit is contained in:
Sibunnayak 2024-09-06 12:46:21 +05:30
parent 8c61d761ce
commit 154f416c7a

View File

@ -134,12 +134,26 @@ export const createretaildistributor = async (req, res) => {
return res.status(400).json({ message: "No files were uploaded." }); 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); // console.log(req.files);
const fertilizerLicenseImg = req.files.fertilizerLicenseImg || null; const fertilizerLicenseImg = req.files.fertilizerLicenseImg || null;
if (!panImg || !aadharImg || !gstImg || !selfieEntranceImg || !pesticideLicenseImg) { if (
return res.status(400).json({ message: "Please upload all required images." }); !panImg ||
!aadharImg ||
!gstImg ||
!selfieEntranceImg ||
!pesticideLicenseImg
) {
return res
.status(400)
.json({ message: "Please upload all required images." });
} }
// Upload images to Cloudinary // Upload images to Cloudinary
@ -157,9 +171,18 @@ export const createretaildistributor = async (req, res) => {
const pan_img = await uploadImage(panImg, "KYC/pan"); const pan_img = await uploadImage(panImg, "KYC/pan");
const aadhar_img = await uploadImage(aadharImg, "KYC/aadhar"); const aadhar_img = await uploadImage(aadharImg, "KYC/aadhar");
const gst_img = await uploadImage(gstImg, "KYC/gst"); const gst_img = await uploadImage(gstImg, "KYC/gst");
const pesticide_license_img = await uploadImage(pesticideLicenseImg, "KYC/pesticide_license"); const pesticide_license_img = await uploadImage(
const fertilizer_license_img= await uploadImage(fertilizerLicenseImg, "KYC/fertilizer_license"); pesticideLicenseImg,
const selfie_entrance_img = await uploadImage(selfieEntranceImg, "KYC/selfie_entrance"); "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 // Create KYC document
const kycData = { const kycData = {
@ -186,7 +209,9 @@ export const createretaildistributor = async (req, res) => {
const kyc = await KYC.create(kycData); const kyc = await KYC.create(kycData);
if (kyc) { 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) { } catch (error) {
res.status(500).json({ res.status(500).json({
@ -355,19 +380,18 @@ export const getAllPrincipalDistributers = async (req, res) => {
try { try {
// Define the filter for the query // Define the filter for the query
let filter = { role: "principal-Distributor" }; let filter = { role: "principal-Distributor" };
// Check the user type and adjust the filter accordingly // Check the user type and adjust the filter accordingly
if (req.userType === "SalesCoOrdinator") { if (req.userType === "SalesCoOrdinator") {
// If userType is "SalesCoOrdinator", filter by req.user.mappedBy // If userType is "SalesCoOrdinator", filter by req.user.mappedBy
filter.mappedBy = req.user.mappedBy; filter.mappedby = req.user.mappedby;
} else { } else {
// Otherwise, filter by req.user._id // 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 // Fetch the principal distributors based on the filter
const principalDistributers = await User.find(filter); const principalDistributers = await User.find(filter);
console.log(principalDistributers);
// Send the fetched data as a response // Send the fetched data as a response
if (principalDistributers.length > 0) { if (principalDistributers.length > 0) {
res.status(200).json(principalDistributers); res.status(200).json(principalDistributers);
@ -380,7 +404,6 @@ export const getAllPrincipalDistributers = async (req, res) => {
} }
}; };
// Fcm token storing // Fcm token storing
export const saveFCMTokenForSC = async (req, res) => { export const saveFCMTokenForSC = async (req, res) => {
const { fcmToken } = req.body; const { fcmToken } = req.body;
@ -458,13 +481,13 @@ export const getAllKycApprovedbytmid = async (req, res) => {
.populate("addedBy") .populate("addedBy")
.skip(skip) .skip(skip)
.limit(parseInt(show)); .limit(parseInt(show));
const total_data = await KYC.countDocuments(query); const total_data = await KYC.countDocuments(query);
// Send the fetched data as a response // Send the fetched data as a response
res.status(200).json({ res.status(200).json({
success: true, success: true,
total_data: total_data, total_data: total_data,
total_pages: Math.ceil(total_data / page), total_pages: Math.ceil(total_data / page),
retaildistributor retaildistributor,
}); });
} catch (error) { } catch (error) {
// Handle any errors that occur during the fetch operation // Handle any errors that occur during the fetch operation