notification-bug-fix (#102)
Some checks failed
Deploy FitLien services to Dev / Deploy to Dev (push) Failing after 1m29s
Some checks failed
Deploy FitLien services to Dev / Deploy to Dev (push) Failing after 1m29s
Co-authored-by: Dhansh A S <dhanshas@cosq.net> Reviewed-on: #102 Reviewed-by: Dhansh A S <dhanshas@cosq.net> Co-authored-by: Sharon Dcruz <sharondcruz@cosq.net> Co-committed-by: Sharon Dcruz <sharondcruz@cosq.net>
This commit is contained in:
parent
b190a371b6
commit
165cd74a17
@ -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[]> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user