api/Utils/rejectKyc.js
2024-09-16 12:54:57 +05:30

50 lines
2.0 KiB
JavaScript

import SalesCoOrdinator from "../resources/SalesCoOrdinators/SalesCoOrdinatorModel.js";
import TerritoryManager from "../resources/TerritoryManagers/TerritoryManagerModel.js";
import User from "../resources/user/userModel.js";
import { sendPushNotification } from "./sendPushNotification.js";
export const rejectKYC = async (userId, title, message) => {
// Try to find the user in SalesCoordinator model
console.log(userId);
let user = await SalesCoOrdinator.findById(userId);
if (!user) {
// If not found, try to find the user in TerritoryManager model
user = await TerritoryManager.findById(userId);
}
console.log(user);
// Get the user's FCM token
const userToken = user ? user.fcm_token : null;
// const userToken =
// "dRnjl8F3S8GA6_BnBfloWZ:APA91bFvuiA4pEQr03Kymqtw2N207VDHwzLlfz_OPWzhTtdAAWmPLF8cQSx0WYmiaL9g-PIbzvGrmzDzxNiyq58w9Gws6p2tDlDeqycqU17W74gi36xkGSUqlzNiFoTiDDNp7OFDdVPK";
console.log(userToken);
if (userToken) {
// Send the push notification
// 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);
}
};
export const createKYC = async (userId, title, message) => {
// Try to find the user in SalesCoordinator model
console.log(userId);
let user = await User.findById(userId);
console.log(user);
// Get the user's FCM token
const userToken = user ? user.fcm_token : null;
// const userToken =
// "dRnjl8F3S8GA6_BnBfloWZ:APA91bFvuiA4pEQr03Kymqtw2N207VDHwzLlfz_OPWzhTtdAAWmPLF8cQSx0WYmiaL9g-PIbzvGrmzDzxNiyq58w9Gws6p2tDlDeqycqU17W74gi36xkGSUqlzNiFoTiDDNp7OFDdVPK";
console.log(userToken);
if (userToken) {
// Send the push notification
// 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);
}
};