expiry-using-payment #81

Merged
dhanshas merged 8 commits from expiry-using-payment into dev 2025-08-05 13:20:02 +00:00
Showing only changes of commit 3c405012b9 - Show all commits

View File

@ -274,6 +274,7 @@ async function processExpiredMembership(
} }
} }
async function sendPlanExpiredNotification( async function sendPlanExpiredNotification(
membershipId: string, membershipId: string,
membershipData: MembershipData membershipData: MembershipData
@ -298,6 +299,7 @@ async function sendPlanExpiredNotification(
let expiryDate: Date | undefined; let expiryDate: Date | undefined;
let formattedDate = "Unknown Date"; let formattedDate = "Unknown Date";
let daysSinceExpiry = 0;
const payments = await getPaymentsForMembership(membershipId); const payments = await getPaymentsForMembership(membershipId);
if (payments.length > 0) { if (payments.length > 0) {
@ -311,6 +313,10 @@ async function sendPlanExpiredNotification(
month: "long", month: "long",
day: "numeric", day: "numeric",
}); });
const now = new Date();
const timeDiff = now.getTime() - expiryDate.getTime();
daysSinceExpiry = Math.floor(timeDiff / (1000 * 3600 * 24));
} }
await app await app
@ -323,6 +329,7 @@ async function sendPlanExpiredNotification(
notificationSent: false, notificationSent: false,
timestamp: admin.firestore.FieldValue.serverTimestamp(), timestamp: admin.firestore.FieldValue.serverTimestamp(),
read: false, read: false,
readBy: [],
data: { data: {
title: "Plan Expired", title: "Plan Expired",
message: `The plan ${ message: `The plan ${
@ -332,7 +339,9 @@ async function sendPlanExpiredNotification(
clientName, clientName,
membershipId, membershipId,
gymName, gymName,
ownerId: gymOwnerId,
formattedExpiryDate: formattedDate, formattedExpiryDate: formattedDate,
daysSinceExpiry,
expiryDate: expiryDate expiryDate: expiryDate
? admin.firestore.Timestamp.fromDate(expiryDate) ? admin.firestore.Timestamp.fromDate(expiryDate)
: admin.firestore.Timestamp.fromDate(new Date()), : admin.firestore.Timestamp.fromDate(new Date()),