created apis for get kyc , get pd
This commit is contained in:
parent
ee36b8b2ff
commit
02f7e34fc6
@ -1,6 +1,7 @@
|
||||
import mongoose from "mongoose";
|
||||
import cloudinary from "../../Utils/cloudinary.js";
|
||||
import { KYC } from "./KycModel.js";
|
||||
import User from "../user/userModel.js";
|
||||
|
||||
export const createKyc = async (req, res) => {
|
||||
const {
|
||||
@ -104,3 +105,58 @@ export const createKyc = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
// Get All KYC
|
||||
export const getAllKyc = async (req, res) => {
|
||||
try {
|
||||
// Fetch all KYC documents from the database
|
||||
const kycs = await KYC.find()
|
||||
.populate("principal_distributer", "name")
|
||||
.populate("addedBy");
|
||||
|
||||
// Send the fetched data as a response
|
||||
res.status(200).json(kycs);
|
||||
} catch (error) {
|
||||
// Handle any errors that occur during the fetch operation
|
||||
res.status(500).json({ message: "Server Error", error });
|
||||
}
|
||||
};
|
||||
// Get Single KYC
|
||||
export const getKycById = async (req, res) => {
|
||||
try {
|
||||
// Get the KYC ID from the request parameters
|
||||
const { id } = req.params;
|
||||
|
||||
// Fetch the KYC document from the database by ID
|
||||
const kyc = await KYC.findById(id)
|
||||
.populate("principal_distributer", "name")
|
||||
.populate("addedBy");
|
||||
|
||||
// Check if the KYC document exists
|
||||
if (!kyc) {
|
||||
return res.status(404).json({ message: "KYC document not found" });
|
||||
}
|
||||
|
||||
// Send the fetched KYC document as a response
|
||||
res.status(200).json(kyc);
|
||||
} catch (error) {
|
||||
// Handle any errors that occur during the fetch operation
|
||||
res.status(500).json({ message: "Server Error", error });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllPrincipalDistributers = async (req, res) => {
|
||||
try {
|
||||
// Fetch all users with the role "principal-distributer"
|
||||
const principalDistributers = await User.find({
|
||||
role: "principal-Distributor",
|
||||
});
|
||||
|
||||
// Send the fetched data as a response
|
||||
if (principalDistributers) {
|
||||
res.status(200).json(principalDistributers);
|
||||
}
|
||||
} catch (error) {
|
||||
// Handle any errors that occur during the fetch operation
|
||||
res.status(500).json({ message: "Server Error", error });
|
||||
}
|
||||
};
|
||||
|
@ -2,8 +2,27 @@ import express from "express";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
import { createKyc } from "./KycController.js";
|
||||
import {
|
||||
createKyc,
|
||||
getAllKyc,
|
||||
getAllPrincipalDistributers,
|
||||
getKycById,
|
||||
} from "./KycController.js";
|
||||
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
||||
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||
router.route("/kyc/create/").post(isAuthenticatedSalesCoOrdinator, createKyc);
|
||||
router
|
||||
.route("/kyc/getAll/")
|
||||
.get(isAuthenticatedUser, authorizeRoles("principal-Distributor"), getAllKyc);
|
||||
router
|
||||
.route("/kyc/get-single-kyc/:id")
|
||||
.get(
|
||||
isAuthenticatedUser,
|
||||
authorizeRoles("principal-Distributor"),
|
||||
getKycById
|
||||
);
|
||||
router
|
||||
.route("/kyc/get-pd/")
|
||||
.get(isAuthenticatedSalesCoOrdinator, getAllPrincipalDistributers);
|
||||
|
||||
export default router;
|
||||
|
Loading…
Reference in New Issue
Block a user