This commit is contained in:
Sibunnayak 2024-08-08 16:05:42 +05:30
commit 1c4fce921c
3 changed files with 31 additions and 12 deletions

View File

@ -2,7 +2,7 @@ import SalesCoOrdinator from "../resources/SalesCoOrdinators/SalesCoOrdinatorMod
import TerritoryManager from "../resources/TerritoryManagers/TerritoryManagerModel.js";
import { sendPushNotification } from "./sendPushNotification.js";
export const rejectKYC = async (userId, reason) => {
export const rejectKYC = async (userId, title, message) => {
// Try to find the user in SalesCoordinator model
console.log(userId);
let user = await SalesCoOrdinator.findById(userId);
@ -18,8 +18,8 @@ export const rejectKYC = async (userId, reason) => {
console.log(userToken);
if (userToken) {
// Send the push notification
const message = `Your KYC has been rejected. Reason: ${reason}`;
await sendPushNotification(userToken, message);
// const message = `Your KYC has been rejected. Reason: ${reason}`;
await sendPushNotification(userToken, title, message);
console.log("sent to device ");
} else {
console.error("No FCM token found for user:", userId);

View File

@ -1,6 +1,6 @@
import admin from "firebase-admin";
import serviceAccount from "../googlefirebasePushnotification.json" with { type: "json" };
export const sendPushNotification = async (userToken, message) => {
export const sendPushNotification = async (userToken,title, message) => {
// const admin = require("firebase-admin");
// const serviceAccount = require("./path/to/your-firebase-adminsdk.json");
@ -12,7 +12,7 @@ export const sendPushNotification = async (userToken, message) => {
const payload = {
notification: {
title: "KYC Rejected ",
title: title,
body: message,
},
token: userToken

View File

@ -203,26 +203,45 @@ export const updateKycStatus = async (req, res) => {
if (kyc.principal_distributer.toString() !== req.user._id.toString()) {
return res.status(403).json({ message: "Access denied" });
}
const trade_name = kyc.trade_name;
if (status === "approved") {
kyc.status = status;
await rejectKYC(
kyc.addedBy,
"KYC Approved",
`Your KYC for ${trade_name} has been approved.`
);
await Notification.create({
title: "KYC Approved",
msg: `Your KYC for ${trade_name} has been approved.`,
kyc_ref: kyc._id,
added_for: kyc.addedBy,
// userType: req.userType,
});
}
if (status === "reject") {
await rejectKYC(kyc.addedBy, rejectionReason);
await rejectKYC(
kyc.addedBy,
"KYC application Rejected",
`KYC for ${trade_name} has been rejected. Reason: ${rejectionReason}`
);
await Notification.create({
title: "KYC Rejected",
msg: rejectionReason,
msg: `KYC for ${trade_name} has been rejected. Reason: ${rejectionReason}`,
kyc_ref: kyc._id,
added_for: kyc.addedBy,
// userType: req.userType,
});
}
// Update the status
if (status) {
kyc.status = status;
}
// if (status) {
// kyc.status = status;
// }
// Add rejection reason to notes if status is reject
if (kyc.status === "reject" || status === "reject") {
// kyc.rejection_reason = rejectionReason;
kyc.status = status;
kyc.notes.push({
message: rejectionReason,
user: user,