Compare commits

...

14 Commits

Author SHA1 Message Date
3f91947c20 Merge branch 'dev' into expiry-notification 2025-08-04 12:58:21 +05:30
29b06a6666 Changes Updated 2025-08-04 12:56:49 +05:30
14b190f891 Changes Updated 2025-08-04 11:13:42 +05:30
e13fdf2a0d Updated 2025-08-04 11:09:51 +05:30
3f4974a74c Chnages Updated 2025-08-04 11:02:41 +05:30
4d61f72cd8 Updated 2025-08-04 10:47:22 +05:30
7fbab4cded Updated 2025-08-04 10:35:48 +05:30
7e6f93a30f Merge branch 'dev' into expiry-notification 2025-08-04 10:30:29 +05:30
d76c84418b Changes Updated 2025-08-04 10:29:00 +05:30
ae90662c28 Merge branch 'dev' into expiry-notification 2025-08-04 10:11:15 +05:30
9327da361c Changes Updated 2025-08-04 10:02:29 +05:30
764c79e1ec Changes UPdated 2025-08-01 21:09:52 +05:30
adec108f8a Changes Updated 2025-08-01 18:25:39 +05:30
5c81ae3016 Changes Updated 2025-08-01 12:24:04 +05:30

View File

@ -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;
}