added update feature
This commit is contained in:
parent
21b632744b
commit
8691d73a88
@ -110,11 +110,11 @@ export const createKyc = async (req, res) => {
|
||||
export const getAllKyc = async (req, res) => {
|
||||
try {
|
||||
// Fetch all KYC documents from the database
|
||||
console.log("req came here ");
|
||||
// console.log("req came here ");
|
||||
const kycs = await KYC.find()
|
||||
.populate("principal_distributer", "name")
|
||||
.populate("addedBy");
|
||||
console.log(kycs);
|
||||
// console.log(kycs);
|
||||
// Send the fetched data as a response
|
||||
res.status(200).json(kycs);
|
||||
} catch (error) {
|
||||
@ -148,8 +148,9 @@ export const getKycById = async (req, res) => {
|
||||
};
|
||||
|
||||
export const updateKycStatus = async (req, res) => {
|
||||
const { status, rejectionReason, userType } = req.body;
|
||||
const { status, rejectionReason, user } = req.body;
|
||||
const { id } = req.params;
|
||||
// console.log(user, rejectionReason, status);
|
||||
try {
|
||||
// Find the KYC document by ID
|
||||
const kyc = await KYC.findById(id);
|
||||
@ -159,14 +160,16 @@ export const updateKycStatus = async (req, res) => {
|
||||
}
|
||||
|
||||
// Update the status
|
||||
kyc.status = status;
|
||||
if (status) {
|
||||
kyc.status = status;
|
||||
}
|
||||
|
||||
// Add rejection reason to notes if status is reject
|
||||
if (status === "reject") {
|
||||
if (kyc.status === "reject" || status === "reject") {
|
||||
// kyc.rejection_reason = rejectionReason;
|
||||
kyc.notes.push({
|
||||
message: rejectionReason,
|
||||
user: userType,
|
||||
user: user,
|
||||
replyDate: new Date(),
|
||||
});
|
||||
}
|
||||
@ -174,7 +177,7 @@ export const updateKycStatus = async (req, res) => {
|
||||
// Save the updated KYC document
|
||||
await kyc.save();
|
||||
|
||||
res.status(200).json({ message: "KYC status updated successfully" });
|
||||
res.status(200).json({ message: "KYC status updated successfully", kyc });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ message: "Error updating KYC status", error });
|
||||
|
@ -88,11 +88,11 @@ const KycSchema = new Schema(
|
||||
addedBy: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
refPath: "userType",
|
||||
required: true,
|
||||
// required: true,
|
||||
},
|
||||
userType: {
|
||||
type: String,
|
||||
required: true,
|
||||
// required: true,
|
||||
enum: ["SalesCoOrdinator", "TerritoryManager"],
|
||||
},
|
||||
notes: [
|
||||
@ -108,7 +108,7 @@ const KycSchema = new Schema(
|
||||
"Sales Co-ordinator",
|
||||
"Territory Manager",
|
||||
],
|
||||
required: true,
|
||||
// required: true,
|
||||
},
|
||||
replyDate: {
|
||||
type: Date,
|
||||
|
Loading…
Reference in New Issue
Block a user