diff --git a/functions/src/notifications/processNotification.ts b/functions/src/notifications/processNotification.ts index a9a5563..8d38599 100644 --- a/functions/src/notifications/processNotification.ts +++ b/functions/src/notifications/processNotification.ts @@ -10,6 +10,7 @@ interface NotificationData { senderId?: string; recipientId?: string; ownerId?: string; + trainerId?: string; type?: string; notificationSent?: boolean; timestamp?: admin.firestore.FieldValue; @@ -86,6 +87,11 @@ async function getUserAndFCMToken( } else if (notification.ownerId) { targetUserId = notification.ownerId; logger.info(`Using top-level ownerId: ${targetUserId}`); + + } else if (notification.trainerId) { + targetUserId = notification.trainerId; + logger.info(`Using top-level trainerId: ${targetUserId}`); + } else if (notification.data?.userId) { targetUserId = notification.data.userId; logger.info(`Using data.userId: ${targetUserId}`); @@ -166,6 +172,7 @@ function prepareNotificationMessage( if (notification.senderId) fcmData.senderId = notification.senderId; if (notification.recipientId) fcmData.recipientId = notification.recipientId; if (notification.ownerId) fcmData.ownerId = notification.ownerId; + if (notification.trainerId) fcmData.trainerId = notification.trainerId; if (notification.read !== undefined) fcmData.read = String(notification.read); if (notification.data) { @@ -185,7 +192,7 @@ function prepareNotificationMessage( case "trainer_response": title = notification.data?.title || - (notification.data?.status === "ACCEPTED" + (notification.data?.status === "accepted" ? "Trainer Request Accepted" : "Trainer Request Update"); body = @@ -199,14 +206,14 @@ function prepareNotificationMessage( title = notification.data?.title || "New Client Assignment"; body = notification.data?.message || - `You have been assigned to ${notification.data?.name}`; + `You have been assigned to train ${notification.data?.name}.`; break; case "trainer_assigned_to_client": title = notification.data?.title || "Trainer Assigned"; body = notification.data?.message || - `${notification.data?.trainerName} has been assigned as your trainer`; + `${notification.data?.trainerName} has been assigned as your trainer.`; break; case "trainer_update_owner":