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