From b190a371b6abd28ce516788bf51c83d06b295d55 Mon Sep 17 00:00:00 2001 From: Sharon Dcruz Date: Tue, 19 Aug 2025 10:21:00 +0000 Subject: [PATCH 1/2] notification-bug-fix (#101) Co-authored-by: Dhansh A S Reviewed-on: https://git.cosqnet.com/cosqnet/fitlien-services/pulls/101 Co-authored-by: Sharon Dcruz Co-committed-by: Sharon Dcruz --- firestore.indexes.json | 165 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/firestore.indexes.json b/firestore.indexes.json index 2ddb5ce..054170d 100644 --- a/firestore.indexes.json +++ b/firestore.indexes.json @@ -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": [] } \ No newline at end of file From 165cd74a17c5773f744c918ddd297b93e645635a Mon Sep 17 00:00:00 2001 From: Sharon Dcruz Date: Tue, 19 Aug 2025 11:18:53 +0000 Subject: [PATCH 2/2] notification-bug-fix (#102) Co-authored-by: Dhansh A S Reviewed-on: https://git.cosqnet.com/cosqnet/fitlien-services/pulls/102 Reviewed-by: Dhansh A S Co-authored-by: Sharon Dcruz Co-committed-by: Sharon Dcruz --- .../membershipStatusNotifications.ts | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/functions/src/notifications/membershipStatusNotifications.ts b/functions/src/notifications/membershipStatusNotifications.ts index ba73340..7e1b88e 100644 --- a/functions/src/notifications/membershipStatusNotifications.ts +++ b/functions/src/notifications/membershipStatusNotifications.ts @@ -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 { 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 { 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 { } } - 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 {