notification-bug-fix #105
@ -53,7 +53,6 @@ export const checkExpiredMemberships = onSchedule(
|
|||||||
logger.info("Starting scheduled membership expiry check...");
|
logger.info("Starting scheduled membership expiry check...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await updateDaysUntilExpiryForAllMemberships();
|
await updateDaysUntilExpiryForAllMemberships();
|
||||||
const expiredMemberships = await findExpiredMemberships();
|
const expiredMemberships = await findExpiredMemberships();
|
||||||
const expiringMemberships = await findMembershipsExpiringIn10Days();
|
const expiringMemberships = await findMembershipsExpiringIn10Days();
|
||||||
@ -381,7 +380,9 @@ function calculateRenewalDateFromPayment(
|
|||||||
|
|
||||||
async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
|
async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
|
||||||
try {
|
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
|
const snapshot = await app
|
||||||
.firestore()
|
.firestore()
|
||||||
@ -401,14 +402,20 @@ async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
|
|||||||
const daysUntilExpiry = await calculateDaysUntilExpiry(doc.id, data);
|
const daysUntilExpiry = await calculateDaysUntilExpiry(doc.id, data);
|
||||||
|
|
||||||
if (daysUntilExpiry !== null) {
|
if (daysUntilExpiry !== null) {
|
||||||
|
const updateData: any = {
|
||||||
|
daysUntilExpiry: daysUntilExpiry,
|
||||||
|
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
||||||
|
};
|
||||||
|
|
||||||
await app
|
await app
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection("memberships")
|
.collection("memberships")
|
||||||
.doc(doc.id)
|
.doc(doc.id)
|
||||||
.update({
|
.update(updateData);
|
||||||
daysUntilExpiry: daysUntilExpiry,
|
|
||||||
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
logger.info(
|
||||||
});
|
`Updated membership ${doc.id} with daysUntilExpiry: ${daysUntilExpiry}`
|
||||||
|
);
|
||||||
return doc.id;
|
return doc.id;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -429,7 +436,6 @@ async function updateDaysUntilExpiryForAllMemberships(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function calculateDaysUntilExpiry(
|
async function calculateDaysUntilExpiry(
|
||||||
membershipId: string,
|
membershipId: string,
|
||||||
data: MembershipData
|
data: MembershipData
|
||||||
@ -459,7 +465,14 @@ async function calculateDaysUntilExpiry(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const now = new Date();
|
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));
|
const daysUntilExpiry = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
||||||
|
|
||||||
return daysUntilExpiry;
|
return daysUntilExpiry;
|
||||||
@ -472,7 +485,6 @@ async function calculateDaysUntilExpiry(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function getTrainerAssignmentsForMembership(
|
async function getTrainerAssignmentsForMembership(
|
||||||
membershipId: string
|
membershipId: string
|
||||||
): Promise<PersonalTrainerAssign[]> {
|
): Promise<PersonalTrainerAssign[]> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user