@timardex/cluemart-server-shared 2.2.21 → 2.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +76 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +82 -32
- package/dist/index.mjs.map +1 -1
- package/dist/service/index.cjs +76 -30
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +14 -1
- package/dist/service/index.d.ts +14 -1
- package/dist/service/index.mjs +82 -32
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/service/index.d.mts
CHANGED
|
@@ -207,11 +207,24 @@ type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
|
|
|
207
207
|
declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
|
|
208
208
|
|
|
209
209
|
type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
|
|
210
|
+
type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
|
|
210
211
|
/**
|
|
211
212
|
* Returns true when at least one startDate/startTime slot from the previous
|
|
212
213
|
* schedule is absent from the next schedule (i.e. a date was removed).
|
|
213
214
|
*/
|
|
214
215
|
declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | undefined, nextDateTime: EventDateSlot[] | undefined): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Returns true when a slot that was `STARTED` in the previous schedule is no
|
|
218
|
+
* longer `STARTED` in the next schedule (e.g. canceled or rescheduled).
|
|
219
|
+
*
|
|
220
|
+
* This catches the `STARTED → CANCELED` transition that
|
|
221
|
+
* {@link didRemoveAnyEventDates} misses: that function only compares
|
|
222
|
+
* `startDate`/`startTime` presence, so a slot that still exists but whose
|
|
223
|
+
* `dateStatus` changed is not flagged. (Its callers filter to future-only
|
|
224
|
+
* schedules, which also drop `STARTED`.) Without this extra status check, a
|
|
225
|
+
* started slot that gets canceled would leave its relation dates untouched.
|
|
226
|
+
*/
|
|
227
|
+
declare function didRemoveAnyStartedDates(previousDateTime: StartedDateSlot[] | undefined, nextDateTime: StartedDateSlot[] | undefined): boolean;
|
|
215
228
|
/**
|
|
216
229
|
* Helper: Update relationDates based on event's dateTime
|
|
217
230
|
* Marks dates as UNAVAILABLE if they no longer exist in the event's dateTime.
|
|
@@ -493,4 +506,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
493
506
|
resourceType: EnumResourceType;
|
|
494
507
|
}): Promise<void>;
|
|
495
508
|
|
|
496
|
-
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
|
509
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
package/dist/service/index.d.ts
CHANGED
|
@@ -207,11 +207,24 @@ type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
|
|
|
207
207
|
declare function findEventOrImportedMarketById(resourceId: ObjectId | string | null | undefined): Promise<EventOrMarket>;
|
|
208
208
|
|
|
209
209
|
type EventDateSlot = Pick<DateTimeType$1, "startDate" | "startTime">;
|
|
210
|
+
type StartedDateSlot = Pick<DateTimeType$1, "dateStatus" | "startDate" | "startTime">;
|
|
210
211
|
/**
|
|
211
212
|
* Returns true when at least one startDate/startTime slot from the previous
|
|
212
213
|
* schedule is absent from the next schedule (i.e. a date was removed).
|
|
213
214
|
*/
|
|
214
215
|
declare function didRemoveAnyEventDates(previousDateTime: EventDateSlot[] | undefined, nextDateTime: EventDateSlot[] | undefined): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Returns true when a slot that was `STARTED` in the previous schedule is no
|
|
218
|
+
* longer `STARTED` in the next schedule (e.g. canceled or rescheduled).
|
|
219
|
+
*
|
|
220
|
+
* This catches the `STARTED → CANCELED` transition that
|
|
221
|
+
* {@link didRemoveAnyEventDates} misses: that function only compares
|
|
222
|
+
* `startDate`/`startTime` presence, so a slot that still exists but whose
|
|
223
|
+
* `dateStatus` changed is not flagged. (Its callers filter to future-only
|
|
224
|
+
* schedules, which also drop `STARTED`.) Without this extra status check, a
|
|
225
|
+
* started slot that gets canceled would leave its relation dates untouched.
|
|
226
|
+
*/
|
|
227
|
+
declare function didRemoveAnyStartedDates(previousDateTime: StartedDateSlot[] | undefined, nextDateTime: StartedDateSlot[] | undefined): boolean;
|
|
215
228
|
/**
|
|
216
229
|
* Helper: Update relationDates based on event's dateTime
|
|
217
230
|
* Marks dates as UNAVAILABLE if they no longer exist in the event's dateTime.
|
|
@@ -493,4 +506,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
493
506
|
resourceType: EnumResourceType;
|
|
494
507
|
}): Promise<void>;
|
|
495
508
|
|
|
496
|
-
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
|
509
|
+
export { ACTIVE_NOT_DELETED_FILTER, type AwardAffiliateVendorSubscriptionRewardsResult, LicenceCategory, type NotificationPubSub, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, SUBSCRIPTION_REWARD_TIMEZONE, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dedupeArchivedSlotsByStartDateTime, didRemoveAnyEventDates, didRemoveAnyStartedDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, persistArchivedEventDates, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, splitEventDatesForArchive, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, upgradeUserToLicence, vendorOwnerHasProLicence };
|
package/dist/service/index.mjs
CHANGED
|
@@ -617,10 +617,17 @@ import {
|
|
|
617
617
|
filterDatesByFutureStatus,
|
|
618
618
|
updateSingleDateTimeStatus
|
|
619
619
|
} from "@timardex/cluemart-shared";
|
|
620
|
-
import
|
|
620
|
+
import dayjs3 from "dayjs";
|
|
621
621
|
|
|
622
622
|
// src/service/event/archiveEndedEventDates.ts
|
|
623
|
-
import {
|
|
623
|
+
import {
|
|
624
|
+
EnumEventDateStatus,
|
|
625
|
+
dateFormat,
|
|
626
|
+
timeFormat
|
|
627
|
+
} from "@timardex/cluemart-shared";
|
|
628
|
+
import dayjs2 from "dayjs";
|
|
629
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
630
|
+
dayjs2.extend(customParseFormat);
|
|
624
631
|
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
625
632
|
EnumEventDateStatus.ENDED
|
|
626
633
|
]);
|
|
@@ -647,6 +654,17 @@ function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
|
647
654
|
return true;
|
|
648
655
|
});
|
|
649
656
|
}
|
|
657
|
+
function isPastCanceledEventDate(slot, now) {
|
|
658
|
+
if (slot.dateStatus !== EnumEventDateStatus.CANCELED) {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
const endDateTime = dayjs2(
|
|
662
|
+
`${slot.endDate} ${slot.endTime}`,
|
|
663
|
+
`${dateFormat} ${timeFormat}`,
|
|
664
|
+
true
|
|
665
|
+
);
|
|
666
|
+
return endDateTime.isValid() && endDateTime.isBefore(now);
|
|
667
|
+
}
|
|
650
668
|
async function persistArchivedEventDates(eventId, slots) {
|
|
651
669
|
if (slots.length === 0) {
|
|
652
670
|
return;
|
|
@@ -711,7 +729,11 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
711
729
|
}
|
|
712
730
|
var ARCHIVABLE_EVENT_FILTER = {
|
|
713
731
|
"dateTime.dateStatus": {
|
|
714
|
-
$in: [
|
|
732
|
+
$in: [
|
|
733
|
+
EnumEventDateStatus2.ENDED,
|
|
734
|
+
EnumEventDateStatus2.INVALID,
|
|
735
|
+
EnumEventDateStatus2.CANCELED
|
|
736
|
+
]
|
|
715
737
|
},
|
|
716
738
|
deletedAt: null
|
|
717
739
|
};
|
|
@@ -726,7 +748,9 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
726
748
|
archiveOps = [];
|
|
727
749
|
}
|
|
728
750
|
if (eventOps.length) {
|
|
729
|
-
await EventModel.bulkWrite(
|
|
751
|
+
await EventModel.bulkWrite(
|
|
752
|
+
eventOps
|
|
753
|
+
);
|
|
730
754
|
eventOps = [];
|
|
731
755
|
}
|
|
732
756
|
};
|
|
@@ -736,7 +760,10 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
736
760
|
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
737
761
|
);
|
|
738
762
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
739
|
-
|
|
763
|
+
const pastCanceled = updated.filter(
|
|
764
|
+
(slot) => isPastCanceledEventDate(slot, now)
|
|
765
|
+
);
|
|
766
|
+
if (archive.length === 0 && discard.length === 0 && pastCanceled.length === 0) {
|
|
740
767
|
continue;
|
|
741
768
|
}
|
|
742
769
|
if (archive.length > 0) {
|
|
@@ -750,16 +777,27 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
750
777
|
});
|
|
751
778
|
archivedCount += uniqueArchive.length;
|
|
752
779
|
}
|
|
780
|
+
const pullConditions = [];
|
|
781
|
+
if (archive.length > 0 || discard.length > 0) {
|
|
782
|
+
pullConditions.push({
|
|
783
|
+
dateStatus: {
|
|
784
|
+
$in: [EnumEventDateStatus2.ENDED, EnumEventDateStatus2.INVALID]
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
for (const slot of pastCanceled) {
|
|
789
|
+
pullConditions.push({
|
|
790
|
+
dateStatus: EnumEventDateStatus2.CANCELED,
|
|
791
|
+
startDate: slot.startDate,
|
|
792
|
+
startTime: slot.startTime
|
|
793
|
+
});
|
|
794
|
+
}
|
|
753
795
|
eventOps.push({
|
|
754
796
|
updateOne: {
|
|
755
797
|
filter: { _id: doc._id },
|
|
756
798
|
update: {
|
|
757
799
|
$pull: {
|
|
758
|
-
dateTime: {
|
|
759
|
-
dateStatus: {
|
|
760
|
-
$in: [EnumEventDateStatus2.ENDED, EnumEventDateStatus2.INVALID]
|
|
761
|
-
}
|
|
762
|
-
}
|
|
800
|
+
dateTime: { $or: pullConditions }
|
|
763
801
|
}
|
|
764
802
|
}
|
|
765
803
|
}
|
|
@@ -815,7 +853,7 @@ async function cleanEventInfoDates(now) {
|
|
|
815
853
|
return removedCount;
|
|
816
854
|
}
|
|
817
855
|
async function updateAllEventDateTimeStatuses() {
|
|
818
|
-
const now =
|
|
856
|
+
const now = dayjs3();
|
|
819
857
|
const [eventCount, marketCount] = await Promise.all([
|
|
820
858
|
updateModelDateTimeStatuses(EventModel, now),
|
|
821
859
|
updateModelDateTimeStatuses(
|
|
@@ -856,6 +894,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
856
894
|
|
|
857
895
|
// src/service/relations.ts
|
|
858
896
|
import {
|
|
897
|
+
EnumEventDateStatus as EnumEventDateStatus3,
|
|
859
898
|
EnumInviteStatus
|
|
860
899
|
} from "@timardex/cluemart-shared";
|
|
861
900
|
function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
@@ -868,6 +907,16 @@ function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
|
|
|
868
907
|
)
|
|
869
908
|
);
|
|
870
909
|
}
|
|
910
|
+
function didRemoveAnyStartedDates(previousDateTime, nextDateTime) {
|
|
911
|
+
if (!previousDateTime?.length) {
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
return previousDateTime.some(
|
|
915
|
+
(prev) => prev.dateStatus === EnumEventDateStatus3.STARTED && !nextDateTime?.some(
|
|
916
|
+
(next) => next.startDate === prev.startDate && next.startTime === prev.startTime && next.dateStatus === EnumEventDateStatus3.STARTED
|
|
917
|
+
)
|
|
918
|
+
);
|
|
919
|
+
}
|
|
871
920
|
function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
872
921
|
return relationDates.map((relationDate) => {
|
|
873
922
|
const existsInEvent = eventDateTime?.some(
|
|
@@ -881,13 +930,13 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
|
|
|
881
930
|
}
|
|
882
931
|
|
|
883
932
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
884
|
-
import
|
|
933
|
+
import dayjs7 from "dayjs";
|
|
885
934
|
|
|
886
935
|
// src/service/license/compliance/utils.ts
|
|
887
936
|
import {
|
|
888
937
|
EnumUserLicence as EnumUserLicence7
|
|
889
938
|
} from "@timardex/cluemart-shared";
|
|
890
|
-
import
|
|
939
|
+
import dayjs6 from "dayjs";
|
|
891
940
|
|
|
892
941
|
// src/service/license/compliance/event.ts
|
|
893
942
|
import { EnumUserLicence as EnumUserLicence3 } from "@timardex/cluemart-shared";
|
|
@@ -1125,7 +1174,7 @@ import {
|
|
|
1125
1174
|
EnumUserLicence as EnumUserLicence6,
|
|
1126
1175
|
vendorLicences
|
|
1127
1176
|
} from "@timardex/cluemart-shared";
|
|
1128
|
-
import
|
|
1177
|
+
import dayjs5 from "dayjs";
|
|
1129
1178
|
|
|
1130
1179
|
// src/service/license/models.ts
|
|
1131
1180
|
import {
|
|
@@ -1134,7 +1183,7 @@ import {
|
|
|
1134
1183
|
isNonVisitorResourceType,
|
|
1135
1184
|
LicenceExpiryDate
|
|
1136
1185
|
} from "@timardex/cluemart-shared";
|
|
1137
|
-
import
|
|
1186
|
+
import dayjs4 from "dayjs";
|
|
1138
1187
|
import { GraphQLError } from "graphql";
|
|
1139
1188
|
var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
|
|
1140
1189
|
LicenceCategory2["EVENT"] = "event";
|
|
@@ -1215,7 +1264,7 @@ function getHighestLicenceForCategory(licences, category) {
|
|
|
1215
1264
|
return highestLicence;
|
|
1216
1265
|
}
|
|
1217
1266
|
function createLicenceObject(expiryDate, licenceType) {
|
|
1218
|
-
const today =
|
|
1267
|
+
const today = dayjs4();
|
|
1219
1268
|
const expiryDateMapping = {
|
|
1220
1269
|
[LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
|
|
1221
1270
|
[LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
|
|
@@ -1478,7 +1527,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
1478
1527
|
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
1479
1528
|
return false;
|
|
1480
1529
|
}
|
|
1481
|
-
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ?
|
|
1530
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs5(stripe.paymentGracePeriodEndsAt) : null;
|
|
1482
1531
|
const hasActivePaymentGracePeriod = (stripe.status === EnumSubscriptionStatus2.PAST_DUE || stripe.status === EnumSubscriptionStatus2.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
1483
1532
|
if (hasActivePaymentGracePeriod) {
|
|
1484
1533
|
return true;
|
|
@@ -1492,7 +1541,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
|
1492
1541
|
if (!stripe.endDate) {
|
|
1493
1542
|
return false;
|
|
1494
1543
|
}
|
|
1495
|
-
const paidThrough =
|
|
1544
|
+
const paidThrough = dayjs5(stripe.endDate);
|
|
1496
1545
|
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
1497
1546
|
}
|
|
1498
1547
|
async function handleVendorLicenceCompliance(user, now) {
|
|
@@ -1509,7 +1558,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
1509
1558
|
(licence) => licence.licenceType !== EnumUserLicence6.STANDARD_VENDOR
|
|
1510
1559
|
);
|
|
1511
1560
|
const expiredProLicences = proLicences.filter(
|
|
1512
|
-
(licence) => !
|
|
1561
|
+
(licence) => !dayjs5(licence.expiryDate).isAfter(now)
|
|
1513
1562
|
);
|
|
1514
1563
|
const stripeProtectedLicenceTypes = new Set(
|
|
1515
1564
|
expiredProLicences.filter(
|
|
@@ -1521,7 +1570,7 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
1521
1570
|
);
|
|
1522
1571
|
const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
|
|
1523
1572
|
const hasExpiredVendorLicence = vendorLicencesOfUser.some(
|
|
1524
|
-
(licence) => !
|
|
1573
|
+
(licence) => !dayjs5(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
|
|
1525
1574
|
);
|
|
1526
1575
|
if (!hasExpiredVendorLicence) {
|
|
1527
1576
|
return;
|
|
@@ -1575,9 +1624,9 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
1575
1624
|
if (!owner) {
|
|
1576
1625
|
return false;
|
|
1577
1626
|
}
|
|
1578
|
-
const now =
|
|
1627
|
+
const now = dayjs5();
|
|
1579
1628
|
const effectiveVendorLicences = owner.licences?.filter(
|
|
1580
|
-
(licence) => licence?.licenceType && (
|
|
1629
|
+
(licence) => licence?.licenceType && (dayjs5(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
1581
1630
|
owner,
|
|
1582
1631
|
licence.licenceType,
|
|
1583
1632
|
now
|
|
@@ -1614,7 +1663,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
|
|
|
1614
1663
|
}
|
|
1615
1664
|
function hasValidLicence(licences, licenceTypes, now) {
|
|
1616
1665
|
return licences.some(
|
|
1617
|
-
(licence) => licenceTypes.includes(licence.licenceType) &&
|
|
1666
|
+
(licence) => licenceTypes.includes(licence.licenceType) && dayjs6(licence.expiryDate).isAfter(now)
|
|
1618
1667
|
);
|
|
1619
1668
|
}
|
|
1620
1669
|
async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
|
|
@@ -1641,7 +1690,7 @@ async function processUserCompliance(user, now) {
|
|
|
1641
1690
|
}
|
|
1642
1691
|
|
|
1643
1692
|
// src/service/license/compliance/ensureUserLicenseCompliance.ts
|
|
1644
|
-
async function ensureUserLicenseComplianceForUser(userId, now =
|
|
1693
|
+
async function ensureUserLicenseComplianceForUser(userId, now = dayjs7()) {
|
|
1645
1694
|
const user = await UserModel.findById(userId);
|
|
1646
1695
|
if (!user) {
|
|
1647
1696
|
return;
|
|
@@ -1649,7 +1698,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = dayjs6()) {
|
|
|
1649
1698
|
await processUserCompliance(user, now);
|
|
1650
1699
|
}
|
|
1651
1700
|
async function ensureUserLicenseCompliance() {
|
|
1652
|
-
const now =
|
|
1701
|
+
const now = dayjs7();
|
|
1653
1702
|
console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
|
|
1654
1703
|
const nowDate = now.toDate();
|
|
1655
1704
|
const users = await UserModel.find({
|
|
@@ -1724,7 +1773,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
|
|
|
1724
1773
|
}
|
|
1725
1774
|
|
|
1726
1775
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
1727
|
-
import
|
|
1776
|
+
import dayjs9 from "dayjs";
|
|
1728
1777
|
|
|
1729
1778
|
// src/service/license/reminder/reminderWindow.ts
|
|
1730
1779
|
var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
|
|
@@ -1732,7 +1781,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
|
|
|
1732
1781
|
|
|
1733
1782
|
// src/service/license/reminder/utils.ts
|
|
1734
1783
|
import {
|
|
1735
|
-
dateFormat,
|
|
1784
|
+
dateFormat as dateFormat2,
|
|
1736
1785
|
EnumNotificationResourceType as EnumNotificationResourceType4,
|
|
1737
1786
|
EnumNotificationType as EnumNotificationType4,
|
|
1738
1787
|
EnumUserLicence as EnumUserLicence8,
|
|
@@ -1740,7 +1789,7 @@ import {
|
|
|
1740
1789
|
vendorLicences as vendorLicences2
|
|
1741
1790
|
} from "@timardex/cluemart-shared";
|
|
1742
1791
|
import { formatDate } from "@timardex/cluemart-shared/utils";
|
|
1743
|
-
import
|
|
1792
|
+
import dayjs8 from "dayjs";
|
|
1744
1793
|
|
|
1745
1794
|
// src/service/license/reminder/vendor.ts
|
|
1746
1795
|
async function getVendorResourceInfo(userId, vendorId) {
|
|
@@ -1799,7 +1848,7 @@ async function checkAndCreateNotification(payload) {
|
|
|
1799
1848
|
}
|
|
1800
1849
|
}
|
|
1801
1850
|
function isLicenseExpiringIn7Days(expiryDate, now) {
|
|
1802
|
-
const expiry =
|
|
1851
|
+
const expiry = dayjs8(expiryDate);
|
|
1803
1852
|
const hoursUntilExpiry = expiry.diff(now, "hour", true);
|
|
1804
1853
|
return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
|
|
1805
1854
|
}
|
|
@@ -1877,7 +1926,7 @@ function getLicenceExpiryMode(licenceType) {
|
|
|
1877
1926
|
}
|
|
1878
1927
|
async function sendLicenseReminder(user, licence) {
|
|
1879
1928
|
const licenceName = getLicenseName(licence.licenceType);
|
|
1880
|
-
const expiryDate =
|
|
1929
|
+
const expiryDate = dayjs8(licence.expiryDate).format(dateFormat2);
|
|
1881
1930
|
const userId = String(user._id);
|
|
1882
1931
|
const resourceInfo = await getLicenseResourceInfo(user, licence);
|
|
1883
1932
|
if (!resourceInfo) {
|
|
@@ -1909,7 +1958,7 @@ async function sendLicenseReminder(user, licence) {
|
|
|
1909
1958
|
console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
|
|
1910
1959
|
}
|
|
1911
1960
|
async function processLicenseReminder(licence, now) {
|
|
1912
|
-
if (
|
|
1961
|
+
if (dayjs8(licence.expiryDate).isBefore(now)) {
|
|
1913
1962
|
return false;
|
|
1914
1963
|
}
|
|
1915
1964
|
if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
|
|
@@ -1963,7 +2012,7 @@ async function processUserLicenseReminders(user, now) {
|
|
|
1963
2012
|
|
|
1964
2013
|
// src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
|
|
1965
2014
|
async function remindUsersAboutLicenseExpiration() {
|
|
1966
|
-
const now =
|
|
2015
|
+
const now = dayjs9();
|
|
1967
2016
|
console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
|
|
1968
2017
|
const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
|
|
1969
2018
|
const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();
|
|
@@ -2015,6 +2064,7 @@ export {
|
|
|
2015
2064
|
createLicenceObject,
|
|
2016
2065
|
dedupeArchivedSlotsByStartDateTime,
|
|
2017
2066
|
didRemoveAnyEventDates,
|
|
2067
|
+
didRemoveAnyStartedDates,
|
|
2018
2068
|
downgradeVendorProFeatures,
|
|
2019
2069
|
ensureUserLicenseCompliance,
|
|
2020
2070
|
ensureUserLicenseComplianceForUser,
|