added the update api
This commit is contained in:
parent
7d01e8c255
commit
7521d592a4
@ -110,14 +110,16 @@ 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 ");
|
||||||
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);
|
||||||
// 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) {
|
||||||
// Handle any errors that occur during the fetch operation
|
// Handle any errors that occur during the fetch operation
|
||||||
|
console.log(error);
|
||||||
res.status(500).json({ message: "Server Error", error });
|
res.status(500).json({ message: "Server Error", error });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -145,6 +147,39 @@ export const getKycById = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateKycStatus = async (req, res) => {
|
||||||
|
const { status, rejectionReason, userType } = req.body;
|
||||||
|
const { id } = req.params;
|
||||||
|
try {
|
||||||
|
// Find the KYC document by ID
|
||||||
|
const kyc = await KYC.findById(id);
|
||||||
|
|
||||||
|
if (!kyc) {
|
||||||
|
return res.status(404).json({ message: "KYC record not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the status
|
||||||
|
kyc.status = status;
|
||||||
|
|
||||||
|
// Add rejection reason to notes if status is reject
|
||||||
|
if (status === "reject") {
|
||||||
|
// kyc.rejection_reason = rejectionReason;
|
||||||
|
kyc.notes.push({
|
||||||
|
message: rejectionReason,
|
||||||
|
user: userType,
|
||||||
|
replyDate: new Date(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the updated KYC document
|
||||||
|
await kyc.save();
|
||||||
|
|
||||||
|
res.status(200).json({ message: "KYC status updated successfully" });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ message: "Error updating KYC status", error });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getAllPrincipalDistributers = async (req, res) => {
|
export const getAllPrincipalDistributers = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Fetch all users with the role "principal-distributer"
|
// Fetch all users with the role "principal-distributer"
|
||||||
|
@ -103,8 +103,12 @@ const KycSchema = new Schema(
|
|||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ["Principal Distributer", "Sales Co-ordinator"],
|
enum: [
|
||||||
default: "Sales Co-ordinator",
|
"Principal Distributer",
|
||||||
|
"Sales Co-ordinator",
|
||||||
|
"Territory Manager",
|
||||||
|
],
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
replyDate: {
|
replyDate: {
|
||||||
type: Date,
|
type: Date,
|
||||||
|
@ -7,10 +7,18 @@ import {
|
|||||||
getAllKyc,
|
getAllKyc,
|
||||||
getAllPrincipalDistributers,
|
getAllPrincipalDistributers,
|
||||||
getKycById,
|
getKycById,
|
||||||
|
updateKycStatus,
|
||||||
} from "./KycController.js";
|
} from "./KycController.js";
|
||||||
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
||||||
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
router.route("/kyc/create/").post(isAuthenticatedSalesCoOrdinator, createKyc);
|
// Pd routes
|
||||||
|
router
|
||||||
|
.route("/kyc/update/:id")
|
||||||
|
.patch(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("principal-Distributor"),
|
||||||
|
updateKycStatus
|
||||||
|
);
|
||||||
router
|
router
|
||||||
.route("/kyc/getAll/")
|
.route("/kyc/getAll/")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("principal-Distributor"), getAllKyc);
|
.get(isAuthenticatedUser, authorizeRoles("principal-Distributor"), getAllKyc);
|
||||||
@ -21,6 +29,9 @@ router
|
|||||||
authorizeRoles("principal-Distributor"),
|
authorizeRoles("principal-Distributor"),
|
||||||
getKycById
|
getKycById
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// sales coordinator routes
|
||||||
|
router.route("/kyc/create/").post(isAuthenticatedSalesCoOrdinator, createKyc);
|
||||||
router
|
router
|
||||||
.route("/kyc/get-pd/")
|
.route("/kyc/get-pd/")
|
||||||
.get(isAuthenticatedSalesCoOrdinator, getAllPrincipalDistributers);
|
.get(isAuthenticatedSalesCoOrdinator, getAllPrincipalDistributers);
|
||||||
|
Loading…
Reference in New Issue
Block a user