api fixed
This commit is contained in:
parent
5a232800e9
commit
23c7508f6e
@ -5,7 +5,7 @@ const KycSchema = new Schema(
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
maxlength: [50, "Name cannot be more than 50 characters"],
|
||||
maxlength: [100, "Name cannot be more than 100 characters"],
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
@ -15,7 +15,7 @@ const KycSchema = new Schema(
|
||||
trade_name: {
|
||||
type: String,
|
||||
required: true,
|
||||
maxlength: [50, "Trade Name cannot be more than 50 characters"],
|
||||
maxlength: [100, "Trade Name cannot be more than 100 characters"],
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
|
@ -1624,7 +1624,8 @@ export const updateRDMapped = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { principal_distributor, mappedTM, mappedSC } = req.body;
|
||||
// console.log(principal_distributor);
|
||||
// console.log(req.body);
|
||||
// console.log(req.params);
|
||||
// Find the RetailDistributor document by ID
|
||||
const RD = await RetailDistributor.findById(id);
|
||||
|
||||
|
@ -20,7 +20,7 @@ const RetailDistributorSchema = new mongoose.Schema(
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
maxlength: [50, "Name cannot be more than 50 characters"],
|
||||
maxlength: [100, "Name cannot be more than 100 characters"],
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
|
@ -153,24 +153,24 @@ export const getAllSales = async (req, res) => {
|
||||
export const getSingleSales = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const Sales = await Sales.findById(id);
|
||||
if (!Sales) {
|
||||
// console.log("id", id);
|
||||
const Sale = await Sales.findById(id);
|
||||
if (!Sale) {
|
||||
return res.status(404).json({ message: "Sales not found" });
|
||||
}
|
||||
|
||||
// console.log("Sales", Sale);
|
||||
// Populate user details based on userType
|
||||
let user = null;
|
||||
if (Sales.userType === "TerritoryManager") {
|
||||
user = await TerritoryManager.findById(Sales.userId);
|
||||
} else if (Sales.userType === "SalesCoOrdinator") {
|
||||
user = await SalesCoordinator.findById(Sales.userId);
|
||||
if (Sale.userType === "TerritoryManager") {
|
||||
user = await TerritoryManager.findById(Sale.userId);
|
||||
} else if (Sale.userType === "SalesCoOrdinator") {
|
||||
user = await SalesCoordinator.findById(Sale.userId);
|
||||
}
|
||||
|
||||
// console.log("user", user);
|
||||
// Populate addedFor details based on addedFor
|
||||
let addedForData = null;
|
||||
if (Sales.addedFor === "PrincipalDistributor") {
|
||||
addedForData = await User.findById(Sales.addedForId);
|
||||
if (Sale.addedFor === "PrincipalDistributor") {
|
||||
addedForData = await User.findById(Sale.addedForId);
|
||||
const shippingAddress = await ShippingAddress.findOne({
|
||||
user: addedForData._id,
|
||||
});
|
||||
@ -178,12 +178,12 @@ export const getSingleSales = async (req, res) => {
|
||||
...addedForData.toObject(),
|
||||
shippingAddress,
|
||||
};
|
||||
} else if (Sales.addedFor === "RetailDistributor") {
|
||||
addedForData = await KYC.findById(Sales.addedForId);
|
||||
} else if (Sale.addedFor === "RetailDistributor") {
|
||||
addedForData = await KYC.findById(Sale.addedForId);
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
...Sales.toObject(),
|
||||
...Sale.toObject(),
|
||||
user,
|
||||
addedForData,
|
||||
});
|
||||
|
@ -242,8 +242,8 @@ export const uploadPrincipaldistributors = async (req, res) => {
|
||||
Name: item.name,
|
||||
phoneNumber: item.phone.toString().trim(),
|
||||
street: item.street,
|
||||
city: item.city,
|
||||
state: item.state,
|
||||
city: item.city.trim(),
|
||||
state: item.state.trim(),
|
||||
postalCode: item.postalCode.toString(),
|
||||
country: "India", // Default country
|
||||
panNumber: item.panNumber,
|
||||
|
Loading…
Reference in New Issue
Block a user