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