api/Utils/rejectKyc.js
2024-08-07 11:22:55 +05:30

24 lines
874 B
JavaScript

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
let user = await SalesCoOrdinator.findById(userId);
if (!user) {
// If not found, try to find the user in TerritoryManager model
user = await TerritoryManager.findById(userId);
}
// Get the user's FCM token
const userToken = user ? user.fcm_token : null;
if (userToken) {
// Send the push notification
const message = `Your KYC has been rejected. Reason: ${reason}`;
await sendPushNotification(userToken, message);
} else {
console.error("No FCM token found for user:", userId);
}
};