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." });
}
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;
@ -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