Changes Updated
This commit is contained in:
parent
14b190f891
commit
29b06a6666
@ -12,7 +12,6 @@ interface MembershipData {
|
||||
status: string;
|
||||
subscription?: {
|
||||
name: string;
|
||||
duration: number;
|
||||
frequency: string;
|
||||
assignedAt: admin.firestore.Timestamp;
|
||||
};
|
||||
@ -88,10 +87,8 @@ async function findExpiredMemberships(): Promise<
|
||||
|
||||
function checkIfMembershipExpired(data: MembershipData): boolean {
|
||||
try {
|
||||
// Critical update: Use the assignedAt timestamp from the subscription object
|
||||
if (
|
||||
!data.subscription ||
|
||||
!data.subscription.duration ||
|
||||
!data.subscription.frequency ||
|
||||
!data.subscription.assignedAt
|
||||
) {
|
||||
@ -106,7 +103,6 @@ function checkIfMembershipExpired(data: MembershipData): boolean {
|
||||
).toDate();
|
||||
const expiryDate = calculateExpiryDate(
|
||||
startDate,
|
||||
data.subscription.duration,
|
||||
data.subscription.frequency
|
||||
);
|
||||
const now = new Date();
|
||||
@ -118,27 +114,23 @@ function checkIfMembershipExpired(data: MembershipData): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function calculateExpiryDate(
|
||||
startDate: Date,
|
||||
duration: number,
|
||||
frequency: string
|
||||
): Date {
|
||||
function calculateExpiryDate(startDate: Date, frequency: string): Date {
|
||||
const expiry = new Date(startDate);
|
||||
switch (frequency.toLowerCase()) {
|
||||
case "monthly":
|
||||
expiry.setMonth(expiry.getMonth() + duration);
|
||||
expiry.setMonth(expiry.getMonth() + 1);
|
||||
break;
|
||||
case "quarterly":
|
||||
expiry.setMonth(expiry.getMonth() + 3 * duration);
|
||||
expiry.setMonth(expiry.getMonth() + 3);
|
||||
break;
|
||||
case "half-yearly":
|
||||
expiry.setMonth(expiry.getMonth() + 6 * duration);
|
||||
expiry.setMonth(expiry.getMonth() + 6);
|
||||
break;
|
||||
case "yearly":
|
||||
expiry.setFullYear(expiry.getFullYear() + duration);
|
||||
expiry.setFullYear(expiry.getFullYear() + 1);
|
||||
break;
|
||||
default:
|
||||
expiry.setMonth(expiry.getMonth() + duration);
|
||||
expiry.setMonth(expiry.getMonth() + 1);
|
||||
}
|
||||
return expiry;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user