notification-bug-fix #105

Merged
dhanshas merged 55 commits from notification-bug-fix into dev 2025-08-20 13:22:29 +00:00
2 changed files with 33 additions and 12 deletions

View File

@ -56,6 +56,34 @@
}
]
},
{
"collectionGroup": "gyms",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "userId",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "gyms",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "isApproved",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "memberships",
"queryScope": "COLLECTION",

View File

@ -465,17 +465,11 @@ async function calculateDaysUntilExpiry(
);
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const expiryDateOnly = new Date(
expiryDate.getFullYear(),
expiryDate.getMonth(),
expiryDate.getDate()
);
const timeDiff = expiryDateOnly.getTime() - today.getTime();
const daysUntilExpiry = Math.ceil(timeDiff / (1000 * 3600 * 24));
const timeDiff = expiryDate.getTime() - now.getTime();
const daysUntilExpiry = Math.floor(timeDiff / (1000 * 3600 * 24));
return daysUntilExpiry;
return Math.max(0, daysUntilExpiry);
} catch (error) {
logger.error(
`Error calculating daysUntilExpiry for membership ${membershipId}:`,
@ -679,7 +673,7 @@ async function sendTrainerNotifications(
if (notificationType === "expiring") {
const now = new Date();
const timeDiff = expiryDate.getTime() - now.getTime();
daysUntilExpiry = Math.ceil(timeDiff / (1000 * 3600 * 24));
daysUntilExpiry = Math.floor(timeDiff / (1000 * 3600 * 24));
}
}
@ -869,7 +863,7 @@ async function sendPlanExpiringNotification(
const now = new Date();
const timeDiff = expiryDate.getTime() - now.getTime();
daysUntilExpiry = Math.ceil(timeDiff / (1000 * 3600 * 24));
daysUntilExpiry = Math.floor(timeDiff / (1000 * 3600 * 24));
}
const existing = await app
@ -929,7 +923,6 @@ async function sendPlanExpiringNotification(
);
}
}
async function getClientName(
membershipId: string,
clientId: string