Compare commits
14 Commits
main
...
expiry-not
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f91947c20 | |||
| 29b06a6666 | |||
| 14b190f891 | |||
| e13fdf2a0d | |||
| 3f4974a74c | |||
| 4d61f72cd8 | |||
| 7fbab4cded | |||
| 7e6f93a30f | |||
| d76c84418b | |||
| ae90662c28 | |||
| 9327da361c | |||
| 764c79e1ec | |||
| adec108f8a | |||
| 5c81ae3016 |
@ -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