import SalesCoOrdinator from "../resources/SalesCoOrdinators/SalesCoOrdinatorModel.js"; import TerritoryManager from "../resources/TerritoryManagers/TerritoryManagerModel.js"; import { sendPushNotification } from "./sendPushNotification.js"; export const rejectKYC = async (userId, reason) => { // 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, message); console.log("sent to device "); } else { console.error("No FCM token found for user:", userId); } };