notification-bug-fix #102

Merged
dhanshas merged 46 commits from notification-bug-fix into dev 2025-08-19 11:18:54 +00:00
2 changed files with 187 additions and 12 deletions

View File

@ -1,4 +1,167 @@
{
"indexes": [],
"indexes": [
{
"collectionGroup": "day_pass_bookings",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "userId",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "day_pass_entries",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "bookingId",
"order": "ASCENDING"
},
{
"fieldPath": "entryDate",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "gyms",
"queryScope": "COLLECTION_GROUP",
"fields": [
{
"fieldPath": "userId",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "gyms",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "userId",
"order": "ASCENDING"
},
{
"fieldPath": "name",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "memberships",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "gymId",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "notifications",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "type",
"order": "ASCENDING"
},
{
"fieldPath": "userId",
"order": "ASCENDING"
},
{
"fieldPath": "timestamp",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "notifications",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "recipientId",
"order": "ASCENDING"
},
{
"fieldPath": "timestamp",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "workout_logs",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "user_id",
"order": "ASCENDING"
},
{
"fieldPath": "date",
"order": "DESCENDING"
}
]
},
{
"collectionGroup": "workout_logs",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "user_id",
"order": "ASCENDING"
},
{
"fieldPath": "date",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "workout_logs",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "user_id",
"order": "ASCENDING"
},
{
"fieldPath": "start_time",
"order": "ASCENDING"
},
{
"fieldPath": "date",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "terms_and_conditions",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "normalizedName",
"order": "ASCENDING"
},
{
"fieldPath": "userUid",
"order": "ASCENDING"
}
]
}
],
"fieldOverrides": []
}

View File

@ -53,7 +53,6 @@ export const checkExpiredMemberships = onSchedule(
logger.info("Starting scheduled membership expiry check...");
try {
await updateDaysUntilExpiryForAllMemberships();
const expiredMemberships = await findExpiredMemberships();
const expiringMemberships = await findMembershipsExpiringIn10Days();
@ -381,8 +380,10 @@ function calculateRenewalDateFromPayment(
async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
try {
logger.info("Starting to update daysUntilExpiry for all active memberships...");
logger.info(
"Starting to update daysUntilExpiry for all active memberships..."
);
const snapshot = await app
.firestore()
.collection("memberships")
@ -399,16 +400,22 @@ async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
batch.map(async (doc) => {
const data = doc.data() as MembershipData;
const daysUntilExpiry = await calculateDaysUntilExpiry(doc.id, data);
if (daysUntilExpiry !== null) {
const updateData: any = {
daysUntilExpiry: daysUntilExpiry,
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
};
await app
.firestore()
.collection("memberships")
.doc(doc.id)
.update({
daysUntilExpiry: daysUntilExpiry,
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
});
.update(updateData);
logger.info(
`Updated membership ${doc.id} with daysUntilExpiry: ${daysUntilExpiry}`
);
return doc.id;
}
return null;
@ -429,7 +436,6 @@ async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
}
}
async function calculateDaysUntilExpiry(
membershipId: string,
data: MembershipData
@ -459,7 +465,14 @@ async function calculateDaysUntilExpiry(
);
const now = new Date();
const timeDiff = expiryDate.getTime() - now.getTime();
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));
return daysUntilExpiry;
@ -472,7 +485,6 @@ async function calculateDaysUntilExpiry(
}
}
async function getTrainerAssignmentsForMembership(
membershipId: string
): Promise<PersonalTrainerAssign[]> {