added kyc create api
This commit is contained in:
parent
ab7b5136b5
commit
a16cda65eb
7
app.js
7
app.js
@ -159,7 +159,8 @@ import ShippingAddressRoute from "./resources/ShippingAddresses/ShippingAddressR
|
|||||||
import stripeRoute from "./resources/StripePayment/stripeRoute.js";
|
import stripeRoute from "./resources/StripePayment/stripeRoute.js";
|
||||||
|
|
||||||
import SeoRoute from "./resources/SEO&Analytics/SEORouter.js";
|
import SeoRoute from "./resources/SEO&Analytics/SEORouter.js";
|
||||||
|
// KYC route
|
||||||
|
import KycRoute from "./resources/KYC/KycRoutes.js";
|
||||||
//Affiliate Routes
|
//Affiliate Routes
|
||||||
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
||||||
//Blog Routes
|
//Blog Routes
|
||||||
@ -170,7 +171,7 @@ import CouponRoute from "./resources/Affiliate&Coupon/Coupon/CouponRoute.js";
|
|||||||
// import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js";
|
// import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js";
|
||||||
//support Ticket
|
//support Ticket
|
||||||
// attandance
|
// attandance
|
||||||
import attendance from "./resources/Attendance/AttandanceRoute.js"
|
import attendance from "./resources/Attendance/AttandanceRoute.js";
|
||||||
//leave
|
//leave
|
||||||
import leave from "./resources/Leaves/LeaveRoute.js";
|
import leave from "./resources/Leaves/LeaveRoute.js";
|
||||||
app.use("/api/v1", user);
|
app.use("/api/v1", user);
|
||||||
@ -194,6 +195,8 @@ app.use("/api/user-address", UserAddressRoute);
|
|||||||
app.use("/api/shipping/address", ShippingAddressRoute);
|
app.use("/api/shipping/address", ShippingAddressRoute);
|
||||||
//SalesCoOrdinator Routes
|
//SalesCoOrdinator Routes
|
||||||
app.use("/api/salescoordinator", SalesCoOrdinatorRoute);
|
app.use("/api/salescoordinator", SalesCoOrdinatorRoute);
|
||||||
|
// Kyc Routes
|
||||||
|
app.use("/api", KycRoute);
|
||||||
|
|
||||||
//Order
|
//Order
|
||||||
app.use("/api/order", orderRoute);
|
app.use("/api/order", orderRoute);
|
||||||
|
@ -22,7 +22,7 @@ export const isAuthenticatedSalesCoOrdinator = async (req, res, next) => {
|
|||||||
const salescoordinator = await SalesCoOrdinator.findById(decoded.id);
|
const salescoordinator = await SalesCoOrdinator.findById(decoded.id);
|
||||||
if (salescoordinator) {
|
if (salescoordinator) {
|
||||||
req.user = salescoordinator;
|
req.user = salescoordinator;
|
||||||
req.userType = 'SalesCoOrdinator';
|
req.userType = "SalesCoOrdinator";
|
||||||
return next();
|
return next();
|
||||||
} else {
|
} else {
|
||||||
return res.status(401).json({
|
return res.status(401).json({
|
||||||
|
98
resources/KYC/KycController.js
Normal file
98
resources/KYC/KycController.js
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
import cloudinary from "../../Utils/cloudinary.js";
|
||||||
|
import { KYC } from "./KycModel.js";
|
||||||
|
export const createKyc = async (req, res) => {
|
||||||
|
const {
|
||||||
|
name,
|
||||||
|
trade_name,
|
||||||
|
address,
|
||||||
|
state,
|
||||||
|
city,
|
||||||
|
district,
|
||||||
|
pincode,
|
||||||
|
mobile_number,
|
||||||
|
principal_distributer,
|
||||||
|
pan_number,
|
||||||
|
aadhar_number,
|
||||||
|
gst_number,
|
||||||
|
addedBy,
|
||||||
|
notes,
|
||||||
|
} = req.body;
|
||||||
|
|
||||||
|
const {
|
||||||
|
fertilizer_license_img,
|
||||||
|
selfie_entrance_img,
|
||||||
|
pan_img,
|
||||||
|
aadhar_img,
|
||||||
|
gst_img,
|
||||||
|
pesticide_license_img,
|
||||||
|
} = req.files;
|
||||||
|
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "Please login!" });
|
||||||
|
try {
|
||||||
|
if (!mongoose.Types.ObjectId.isValid(req.user._id)) {
|
||||||
|
return res.status(400).json({ message: "Please login again" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload images to Cloudinary and store only public_id and url
|
||||||
|
const uploadImage = async (image, folder) => {
|
||||||
|
const result = await cloudinary.v2.uploader.upload(image.tempFilePath, {
|
||||||
|
folder,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
public_id: result.public_id,
|
||||||
|
url: result.secure_url,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const panImg = await uploadImage(pan_img, "KYC/pan");
|
||||||
|
const aadharImg = await uploadImage(aadhar_img, "KYC/aadhar");
|
||||||
|
const gstImg = await uploadImage(gst_img, "KYC/gst");
|
||||||
|
const pesticideLicenseImg = await uploadImage(
|
||||||
|
pesticide_license_img,
|
||||||
|
"KYC/pesticide_license"
|
||||||
|
);
|
||||||
|
const fertilizerLicenseImg = fertilizer_license_img
|
||||||
|
? await uploadImage(fertilizer_license_img, "KYC/fertilizer_license")
|
||||||
|
: null;
|
||||||
|
const selfieEntranceImg = await uploadImage(
|
||||||
|
selfie_entrance_img,
|
||||||
|
"KYC/selfie_entrance"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create KYC document
|
||||||
|
const kyc = await KYC.create({
|
||||||
|
name,
|
||||||
|
trade_name,
|
||||||
|
address,
|
||||||
|
state,
|
||||||
|
city,
|
||||||
|
district,
|
||||||
|
pincode,
|
||||||
|
mobile_number,
|
||||||
|
principal_distributer,
|
||||||
|
pan_number,
|
||||||
|
pan_img: panImg,
|
||||||
|
aadhar_number,
|
||||||
|
aadhar_img: aadharImg,
|
||||||
|
gst_number,
|
||||||
|
gst_img: gstImg,
|
||||||
|
pesticide_license_img: pesticideLicenseImg,
|
||||||
|
fertilizer_license_img: fertilizerLicenseImg,
|
||||||
|
selfie_entrance_img: selfieEntranceImg,
|
||||||
|
addedBy: req.user._id,
|
||||||
|
notes,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (kyc) {
|
||||||
|
return res
|
||||||
|
.status(201)
|
||||||
|
.json({ success: true, kyc, message: "KYC created" });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
113
resources/KYC/KycModel.js
Normal file
113
resources/KYC/KycModel.js
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import mongoose, { Schema, model } from "mongoose";
|
||||||
|
|
||||||
|
const KycSchema = new Schema(
|
||||||
|
{
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
maxlength: [50, "Name cannot be more than 50 characters"],
|
||||||
|
},
|
||||||
|
trade_name: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
maxlength: [50, "Trade Name cannot be more than 50 characters"],
|
||||||
|
},
|
||||||
|
address: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
state: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
city: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
district: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
pincode: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
mobile_number: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
principal_distributer: {
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
pan_number: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
pan_img: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
aadhar_number: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
aadhar_img: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
gst_number: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
gst_img: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
pesticide_license_img: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
fertilizer_license_img: {
|
||||||
|
type: Object,
|
||||||
|
},
|
||||||
|
selfie_entrance_img: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: String,
|
||||||
|
enum: ["new", "reject", "approved"],
|
||||||
|
default: "new",
|
||||||
|
},
|
||||||
|
rejection_reason: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
addedBy: {
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: "SalesCoOrdinator",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
notes: [
|
||||||
|
{
|
||||||
|
message: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
type: String,
|
||||||
|
enum: ["Principal Distributer", "Sales Co-ordinator"],
|
||||||
|
default: "Sales Co-ordinator",
|
||||||
|
},
|
||||||
|
replyDate: {
|
||||||
|
type: Date,
|
||||||
|
default: Date.now,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const KYC = model("KYC", KycSchema);
|
9
resources/KYC/KycRoutes.js
Normal file
9
resources/KYC/KycRoutes.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import express from "express";
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
import { createKyc } from "./KycController.js";
|
||||||
|
import { isAuthenticatedSalesCoOrdinator } from "../../middlewares/SalesCoOrdinatorAuth.js";
|
||||||
|
router.route("/kyc/create/").post(isAuthenticatedSalesCoOrdinator, createKyc);
|
||||||
|
|
||||||
|
export default router;
|
Loading…
Reference in New Issue
Block a user