updated savefcm
This commit is contained in:
parent
bd884a4e93
commit
7879774886
@ -4,19 +4,23 @@ import { sendPushNotification } from "./sendPushNotification.js";
|
|||||||
|
|
||||||
export const rejectKYC = async (userId, reason) => {
|
export const rejectKYC = async (userId, reason) => {
|
||||||
// Try to find the user in SalesCoordinator model
|
// Try to find the user in SalesCoordinator model
|
||||||
|
console.log(userId);
|
||||||
let user = await SalesCoOrdinator.findById(userId);
|
let user = await SalesCoOrdinator.findById(userId);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// If not found, try to find the user in TerritoryManager model
|
// If not found, try to find the user in TerritoryManager model
|
||||||
user = await TerritoryManager.findById(userId);
|
user = await TerritoryManager.findById(userId);
|
||||||
}
|
}
|
||||||
|
console.log(user);
|
||||||
// Get the user's FCM token
|
// Get the user's FCM token
|
||||||
const userToken = user ? user.fcm_token : null;
|
const userToken = user ? user.fcm_token : null;
|
||||||
|
// const userToken =
|
||||||
|
// "dRnjl8F3S8GA6_BnBfloWZ:APA91bFvuiA4pEQr03Kymqtw2N207VDHwzLlfz_OPWzhTtdAAWmPLF8cQSx0WYmiaL9g-PIbzvGrmzDzxNiyq58w9Gws6p2tDlDeqycqU17W74gi36xkGSUqlzNiFoTiDDNp7OFDdVPK";
|
||||||
|
console.log(userToken);
|
||||||
if (userToken) {
|
if (userToken) {
|
||||||
// Send the push notification
|
// Send the push notification
|
||||||
const message = `Your KYC has been rejected. Reason: ${reason}`;
|
const message = `Your KYC has been rejected. Reason: ${reason}`;
|
||||||
await sendPushNotification(userToken, message);
|
await sendPushNotification(userToken, message);
|
||||||
|
console.log("sent to device ");
|
||||||
} else {
|
} else {
|
||||||
console.error("No FCM token found for user:", userId);
|
console.error("No FCM token found for user:", userId);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ export const sendPushNotification = async (userToken, message) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await admin.messaging().send(message);
|
const response = await admin.messaging().send(payload);
|
||||||
console.log("Successfully sent message:", response);
|
console.log("Successfully sent message:", response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error sending message:", error);
|
console.error("Error sending message:", error);
|
||||||
|
@ -205,13 +205,13 @@ export const updateKycStatus = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (status === "reject") {
|
if (status === "reject") {
|
||||||
await rejectKYC(req.user._id, rejectionReason);
|
await rejectKYC(kyc.addedBy, rejectionReason);
|
||||||
await Notification.create({
|
await Notification.create({
|
||||||
title: "KYC Rejected",
|
title: "KYC Rejected",
|
||||||
msg: rejectionReason,
|
msg: rejectionReason,
|
||||||
kyc_ref: kyc._id,
|
kyc_ref: kyc._id,
|
||||||
added_for: req.user._id,
|
added_for: kyc.addedBy,
|
||||||
userType: req.userType,
|
// userType: req.userType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Update the status
|
// Update the status
|
||||||
@ -271,7 +271,7 @@ export const saveFCMTokenForSC = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the new FCM token is different from the current one
|
// Check if the new FCM token is different from the current one
|
||||||
if (user.fcm_token === fcmToken) {
|
if (user.fcm_token && user.fcm_token === fcmToken) {
|
||||||
return res.status(200).send("FCM Token is already up to date");
|
return res.status(200).send("FCM Token is already up to date");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ export const saveFCMTokenForTM = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the new FCM token is different from the current one
|
// Check if the new FCM token is different from the current one
|
||||||
if (user.fcm_token === fcmToken) {
|
if (user.fcm_token && user.fcm_token === fcmToken) {
|
||||||
return res.status(200).send("FCM Token is already up to date");
|
return res.status(200).send("FCM Token is already up to date");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@ const notificationSchema = new Schema(
|
|||||||
},
|
},
|
||||||
added_for: {
|
added_for: {
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
refPath: "userType",
|
// refPath: "KYC",
|
||||||
required: true, // Assuming this should be required
|
// required: true, // Assuming this should be required
|
||||||
},
|
|
||||||
userType: {
|
|
||||||
type: String,
|
|
||||||
required: true, // Assuming this should be required
|
|
||||||
enum: ["SalesCoOrdinator", "TerritoryManager"],
|
|
||||||
},
|
},
|
||||||
|
// userType: {
|
||||||
|
// type: String,
|
||||||
|
// required: true, // Assuming this should be required
|
||||||
|
// enum: ["SalesCoOrdinator", "TerritoryManager"],
|
||||||
|
// },
|
||||||
},
|
},
|
||||||
{ timestamps: true } // Adds createdAt and updatedAt timestamps
|
{ timestamps: true } // Adds createdAt and updatedAt timestamps
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user