added update feature

This commit is contained in:
ROSHAN GARG 2024-08-02 17:57:36 +05:30
parent 21b632744b
commit 8691d73a88
2 changed files with 13 additions and 10 deletions

View File

@ -110,11 +110,11 @@ export const createKyc = async (req, res) => {
export const getAllKyc = async (req, res) => { export const getAllKyc = async (req, res) => {
try { try {
// Fetch all KYC documents from the database // Fetch all KYC documents from the database
console.log("req came here "); // console.log("req came here ");
const kycs = await KYC.find() const kycs = await KYC.find()
.populate("principal_distributer", "name") .populate("principal_distributer", "name")
.populate("addedBy"); .populate("addedBy");
console.log(kycs); // console.log(kycs);
// Send the fetched data as a response // Send the fetched data as a response
res.status(200).json(kycs); res.status(200).json(kycs);
} catch (error) { } catch (error) {
@ -148,8 +148,9 @@ export const getKycById = async (req, res) => {
}; };
export const updateKycStatus = 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; const { id } = req.params;
// console.log(user, rejectionReason, status);
try { try {
// Find the KYC document by ID // Find the KYC document by ID
const kyc = await KYC.findById(id); const kyc = await KYC.findById(id);
@ -159,14 +160,16 @@ export const updateKycStatus = async (req, res) => {
} }
// Update the status // Update the status
if (status) {
kyc.status = status; kyc.status = status;
}
// Add rejection reason to notes if status is reject // Add rejection reason to notes if status is reject
if (status === "reject") { if (kyc.status === "reject" || status === "reject") {
// kyc.rejection_reason = rejectionReason; // kyc.rejection_reason = rejectionReason;
kyc.notes.push({ kyc.notes.push({
message: rejectionReason, message: rejectionReason,
user: userType, user: user,
replyDate: new Date(), replyDate: new Date(),
}); });
} }
@ -174,7 +177,7 @@ export const updateKycStatus = async (req, res) => {
// Save the updated KYC document // Save the updated KYC document
await kyc.save(); await kyc.save();
res.status(200).json({ message: "KYC status updated successfully" }); res.status(200).json({ message: "KYC status updated successfully", kyc });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ message: "Error updating KYC status", error }); res.status(500).json({ message: "Error updating KYC status", error });

View File

@ -88,11 +88,11 @@ const KycSchema = new Schema(
addedBy: { addedBy: {
type: mongoose.Schema.Types.ObjectId, type: mongoose.Schema.Types.ObjectId,
refPath: "userType", refPath: "userType",
required: true, // required: true,
}, },
userType: { userType: {
type: String, type: String,
required: true, // required: true,
enum: ["SalesCoOrdinator", "TerritoryManager"], enum: ["SalesCoOrdinator", "TerritoryManager"],
}, },
notes: [ notes: [
@ -108,7 +108,7 @@ const KycSchema = new Schema(
"Sales Co-ordinator", "Sales Co-ordinator",
"Territory Manager", "Territory Manager",
], ],
required: true, // required: true,
}, },
replyDate: { replyDate: {
type: Date, type: Date,