api given to sibun , vaibh , krati

This commit is contained in:
ROSHAN GARG 2024-08-05 10:54:07 +05:30
parent 8691d73a88
commit c82b44ce33
2 changed files with 62 additions and 2 deletions

View File

@ -123,6 +123,41 @@ export const getAllKyc = async (req, res) => {
res.status(500).json({ message: "Server Error", error }); res.status(500).json({ message: "Server Error", error });
} }
}; };
// Get all KYC Rejected
export const getAllKycRejected = async (req, res) => {
try {
// Fetch all KYC documents from the database
// console.log("req came here ");
const kycs = await KYC.find({ status: "reject", addedBy: req.user._id })
.populate("principal_distributer", "name")
.populate("addedBy");
// console.log(kycs);
// Send the fetched data as a response
res.status(200).json(kycs);
} catch (error) {
// Handle any errors that occur during the fetch operation
console.log(error);
res.status(500).json({ message: "Server Error", error });
}
};
// Get All KYC Approved
export const getAllKycApproved = async (req, res) => {
try {
// Fetch all KYC documents from the database
// console.log("req came here ");
const kycs = await KYC.find({ status: "approved" })
.populate("principal_distributer", "name")
.populate("addedBy");
// console.log(kycs);
// Send the fetched data as a response
res.status(200).json(kycs);
} catch (error) {
// Handle any errors that occur during the fetch operation
console.log(error);
res.status(500).json({ message: "Server Error", error });
}
};
// Get Single KYC // Get Single KYC
export const getKycById = async (req, res) => { export const getKycById = async (req, res) => {
try { try {

View File

@ -5,12 +5,15 @@ const router = express.Router();
import { import {
createKyc, createKyc,
getAllKyc, getAllKyc,
getAllKycApproved,
getAllKycRejected,
getAllPrincipalDistributers, getAllPrincipalDistributers,
getKycById, getKycById,
updateKycStatus, 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";
import { isAuthenticatedTerritoryManager } from "../../middlewares/TerritoryManagerAuth.js";
// Pd routes // Pd routes
router router
.route("/kyc/update/:id") .route("/kyc/update/:id")
@ -22,18 +25,40 @@ router
router router
.route("/kyc/getAll/") .route("/kyc/getAll/")
.get(isAuthenticatedUser, authorizeRoles("principal-Distributor"), getAllKyc); .get(isAuthenticatedUser, authorizeRoles("principal-Distributor"), getAllKyc);
router
.route("/kyc/getAllapproved/")
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllKycApproved);
router router
.route("/kyc/get-single-kyc/:id") .route("/kyc/get-single-kyc/:id")
.get( .get(
isAuthenticatedUser, isAuthenticatedUser,
authorizeRoles("principal-Distributor"), authorizeRoles("admin", "principal-Distributor"),
getKycById getKycById
); );
// sales coordinator routes // sales coordinator routes && TM ROUTES
router.route("/kyc/create/").post(isAuthenticatedSalesCoOrdinator, createKyc); router.route("/kyc/create/").post(isAuthenticatedSalesCoOrdinator, createKyc);
router
.route("/kyc/create-tm/")
.post(isAuthenticatedTerritoryManager, createKyc);
router
.route("/kyc/getAllrejected/")
.get(isAuthenticatedSalesCoOrdinator, getAllKycRejected);
router
.route("/kyc/getAllrejected-tm/")
.get(isAuthenticatedTerritoryManager, getAllKycRejected);
router router
.route("/kyc/get-pd/") .route("/kyc/get-pd/")
.get(isAuthenticatedSalesCoOrdinator, getAllPrincipalDistributers); .get(isAuthenticatedSalesCoOrdinator, getAllPrincipalDistributers);
router
.route("/kyc/get-pd-tm/")
.get(isAuthenticatedTerritoryManager, getAllPrincipalDistributers);
router
.route("/kyc/get-single-kyc-sc/:id")
.get(isAuthenticatedSalesCoOrdinator, getKycById);
router
.route("/kyc/get-single-kyc-tm/:id")
.get(isAuthenticatedSalesCoOrdinator, getKycById);
export default router; export default router;