notification-bug-fix (#105)
Some checks failed
Deploy FitLien services to Dev / Deploy to Dev (push) Failing after 1m52s

Co-authored-by: Dhansh A S <dhanshas@cosq.net>
Reviewed-on: #105
Co-authored-by: Sharon Dcruz <sharondcruz@cosq.net>
Co-committed-by: Sharon Dcruz <sharondcruz@cosq.net>
This commit is contained in:
Sharon Dcruz 2025-08-20 13:22:29 +00:00 committed by Dhansh A S
parent 70d76bab2e
commit f93931867c
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