@timardex/cluemart-server-shared 2.1.7 → 2.1.11
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/{Affiliate-Dlf_OLIh.d.ts → Affiliate-BSF7Wm6O.d.ts} +2 -32
- package/dist/{Affiliate-B1mxoMeD.d.mts → Affiliate-i11rkfv5.d.mts} +2 -32
- package/dist/{chunk-OVAGFPTP.mjs → chunk-HLRUWJLN.mjs} +314 -330
- package/dist/chunk-HLRUWJLN.mjs.map +1 -0
- package/dist/index.cjs +564 -417
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +41 -33
- package/dist/index.d.ts +41 -33
- package/dist/index.mjs +486 -341
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +309 -325
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +14 -4
- package/dist/mongoose/index.d.ts +14 -4
- package/dist/mongoose/index.mjs +3 -3
- package/dist/service/index.cjs +560 -413
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +31 -3
- package/dist/service/index.d.ts +31 -3
- package/dist/service/index.mjs +175 -12
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-OVAGFPTP.mjs.map +0 -1
package/dist/service/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
3
|
import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
4
|
-
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-
|
|
4
|
+
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-i11rkfv5.mjs';
|
|
5
5
|
import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.mjs';
|
|
6
6
|
import dayjs, { Dayjs } from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
@@ -166,10 +166,38 @@ declare function convertObjectIdsToStrings(obj: any): any;
|
|
|
166
166
|
*/
|
|
167
167
|
declare function updateSingleDateTimeStatus<T extends DateTimeType>(dateTime: T, now?: dayjs.Dayjs): T;
|
|
168
168
|
/**
|
|
169
|
-
* Recomputes dateStatus for every dateTime slot on events and google imported
|
|
169
|
+
* Recomputes dateStatus for every dateTime slot on events and google imported
|
|
170
|
+
* markets, moves ended event date slots into the event date archive, and keeps
|
|
171
|
+
* `EventInfo.dateTime` future-only.
|
|
170
172
|
*/
|
|
171
173
|
declare function updateAllEventDateTimeStatuses(): Promise<void>;
|
|
172
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Splits a recomputed event schedule into three buckets: slots to keep on the
|
|
177
|
+
* Event document (future + STARTED), ended slots to archive (`ENDED`), and
|
|
178
|
+
* invalid slots to discard (`INVALID` — removed from the Event but *not*
|
|
179
|
+
* archived). `Event.dateTime` may become empty once an event has no future or
|
|
180
|
+
* in-progress dates.
|
|
181
|
+
*/
|
|
182
|
+
declare function splitEventDatesForArchive(dateTime: DateTimeType[]): {
|
|
183
|
+
archive: DateTimeType[];
|
|
184
|
+
discard: DateTimeType[];
|
|
185
|
+
keep: DateTimeType[];
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* De-duplicates the *input* slots on (startDate, startTime), keeping the first
|
|
189
|
+
* occurrence. This prevents a single write from appending near-duplicate
|
|
190
|
+
* history (the archive's `$addToSet` only de-dupes by deep equality, not by
|
|
191
|
+
* startDate/startTime). It does not scan or clean duplicates already stored in
|
|
192
|
+
* the archive document.
|
|
193
|
+
*/
|
|
194
|
+
declare function dedupeArchivedSlotsByStartDateTime(slots: DateTimeType[]): DateTimeType[];
|
|
195
|
+
/**
|
|
196
|
+
* Persists archived slots into the event's archive document. Idempotent: the
|
|
197
|
+
* archive document is keyed per event and slots are appended with `$addToSet`.
|
|
198
|
+
*/
|
|
199
|
+
declare function persistArchivedEventDates(eventId: ObjectId | string, slots: DateTimeType[]): Promise<void>;
|
|
200
|
+
|
|
173
201
|
type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
|
|
174
202
|
/** Present on owned EventModel docs; absent on Google-imported markets. */
|
|
175
203
|
owner?: SchemaOwnerType;
|
|
@@ -471,4 +499,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
471
499
|
resourceType: EnumResourceType;
|
|
472
500
|
}): Promise<void>;
|
|
473
501
|
|
|
474
|
-
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, 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, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, upgradeUserToLicence, vendorOwnerHasProLicence };
|
|
502
|
+
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, updateSingleDateTimeStatus, upgradeUserToLicence, vendorOwnerHasProLicence };
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as mongoose from 'mongoose';
|
|
2
2
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
3
3
|
import { PromoCodeType, EnumAffiliateRewardType, DateTimeType, EventListItemType, DateTimeWithPriceType, EnumUserLicence as EnumUserLicence$1, UserLicenceType, EnumNotificationResourceType, EnumNotificationType, EnumResourceType, LicenceExpiryDate } from '@timardex/cluemart-shared';
|
|
4
|
-
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-
|
|
4
|
+
import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-BSF7Wm6O.js';
|
|
5
5
|
import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.js';
|
|
6
6
|
import dayjs, { Dayjs } from 'dayjs';
|
|
7
7
|
import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
|
|
@@ -166,10 +166,38 @@ declare function convertObjectIdsToStrings(obj: any): any;
|
|
|
166
166
|
*/
|
|
167
167
|
declare function updateSingleDateTimeStatus<T extends DateTimeType>(dateTime: T, now?: dayjs.Dayjs): T;
|
|
168
168
|
/**
|
|
169
|
-
* Recomputes dateStatus for every dateTime slot on events and google imported
|
|
169
|
+
* Recomputes dateStatus for every dateTime slot on events and google imported
|
|
170
|
+
* markets, moves ended event date slots into the event date archive, and keeps
|
|
171
|
+
* `EventInfo.dateTime` future-only.
|
|
170
172
|
*/
|
|
171
173
|
declare function updateAllEventDateTimeStatuses(): Promise<void>;
|
|
172
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Splits a recomputed event schedule into three buckets: slots to keep on the
|
|
177
|
+
* Event document (future + STARTED), ended slots to archive (`ENDED`), and
|
|
178
|
+
* invalid slots to discard (`INVALID` — removed from the Event but *not*
|
|
179
|
+
* archived). `Event.dateTime` may become empty once an event has no future or
|
|
180
|
+
* in-progress dates.
|
|
181
|
+
*/
|
|
182
|
+
declare function splitEventDatesForArchive(dateTime: DateTimeType[]): {
|
|
183
|
+
archive: DateTimeType[];
|
|
184
|
+
discard: DateTimeType[];
|
|
185
|
+
keep: DateTimeType[];
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* De-duplicates the *input* slots on (startDate, startTime), keeping the first
|
|
189
|
+
* occurrence. This prevents a single write from appending near-duplicate
|
|
190
|
+
* history (the archive's `$addToSet` only de-dupes by deep equality, not by
|
|
191
|
+
* startDate/startTime). It does not scan or clean duplicates already stored in
|
|
192
|
+
* the archive document.
|
|
193
|
+
*/
|
|
194
|
+
declare function dedupeArchivedSlotsByStartDateTime(slots: DateTimeType[]): DateTimeType[];
|
|
195
|
+
/**
|
|
196
|
+
* Persists archived slots into the event's archive document. Idempotent: the
|
|
197
|
+
* archive document is keyed per event and slots are appended with `$addToSet`.
|
|
198
|
+
*/
|
|
199
|
+
declare function persistArchivedEventDates(eventId: ObjectId | string, slots: DateTimeType[]): Promise<void>;
|
|
200
|
+
|
|
173
201
|
type EventOrMarket = (Pick<EventListItemType, "_id" | "name" | "dateTime"> & {
|
|
174
202
|
/** Present on owned EventModel docs; absent on Google-imported markets. */
|
|
175
203
|
owner?: SchemaOwnerType;
|
|
@@ -471,4 +499,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
471
499
|
resourceType: EnumResourceType;
|
|
472
500
|
}): Promise<void>;
|
|
473
501
|
|
|
474
|
-
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, 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, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, syncUserLicencesAfterExpiry, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, upgradeUserToLicence, vendorOwnerHasProLicence };
|
|
502
|
+
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, updateSingleDateTimeStatus, upgradeUserToLicence, vendorOwnerHasProLicence };
|
package/dist/service/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AdModel,
|
|
3
3
|
AffiliateModel,
|
|
4
|
+
EventDateArchiveModel,
|
|
5
|
+
EventInfoModel,
|
|
4
6
|
EventModel,
|
|
5
7
|
GoogleImportedMarketModel,
|
|
6
8
|
NotificationModel,
|
|
@@ -8,7 +10,7 @@ import {
|
|
|
8
10
|
PushTokenModel,
|
|
9
11
|
UserModel,
|
|
10
12
|
VendorModel
|
|
11
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-HLRUWJLN.mjs";
|
|
12
14
|
import "../chunk-6PNG5BI5.mjs";
|
|
13
15
|
|
|
14
16
|
// src/service/promoCode/constants.ts
|
|
@@ -614,32 +616,75 @@ function convertObjectIdsToStrings(obj) {
|
|
|
614
616
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
615
617
|
import {
|
|
616
618
|
dateFormat,
|
|
617
|
-
EnumEventDateStatus,
|
|
619
|
+
EnumEventDateStatus as EnumEventDateStatus2,
|
|
620
|
+
filterDatesByFutureStatus,
|
|
618
621
|
timeFormat
|
|
619
622
|
} from "@timardex/cluemart-shared";
|
|
620
623
|
import dayjs2 from "dayjs";
|
|
621
624
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
622
625
|
import isoWeek from "dayjs/plugin/isoWeek";
|
|
626
|
+
|
|
627
|
+
// src/service/event/archiveEndedEventDates.ts
|
|
628
|
+
import { EnumEventDateStatus } from "@timardex/cluemart-shared";
|
|
629
|
+
var ARCHIVED_STATUSES = /* @__PURE__ */ new Set([
|
|
630
|
+
EnumEventDateStatus.ENDED
|
|
631
|
+
]);
|
|
632
|
+
var DISCARDED_STATUSES = /* @__PURE__ */ new Set([
|
|
633
|
+
EnumEventDateStatus.INVALID
|
|
634
|
+
]);
|
|
635
|
+
function splitEventDatesForArchive(dateTime) {
|
|
636
|
+
return {
|
|
637
|
+
archive: dateTime.filter((slot) => ARCHIVED_STATUSES.has(slot.dateStatus)),
|
|
638
|
+
discard: dateTime.filter((slot) => DISCARDED_STATUSES.has(slot.dateStatus)),
|
|
639
|
+
keep: dateTime.filter(
|
|
640
|
+
(slot) => !ARCHIVED_STATUSES.has(slot.dateStatus) && !DISCARDED_STATUSES.has(slot.dateStatus)
|
|
641
|
+
)
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function dedupeArchivedSlotsByStartDateTime(slots) {
|
|
645
|
+
const seen = /* @__PURE__ */ new Set();
|
|
646
|
+
return slots.filter((slot) => {
|
|
647
|
+
const key = `${slot.startDate}_${slot.startTime}`;
|
|
648
|
+
if (seen.has(key)) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
seen.add(key);
|
|
652
|
+
return true;
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
async function persistArchivedEventDates(eventId, slots) {
|
|
656
|
+
if (slots.length === 0) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const uniqueSlots = dedupeArchivedSlotsByStartDateTime(slots);
|
|
660
|
+
await EventDateArchiveModel.updateOne(
|
|
661
|
+
{ eventId },
|
|
662
|
+
{ $addToSet: { dateTime: { $each: uniqueSlots } } },
|
|
663
|
+
{ upsert: true }
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
623
668
|
dayjs2.extend(customParseFormat);
|
|
624
669
|
dayjs2.extend(isoWeek);
|
|
625
670
|
function getFutureEventStatus(startDateTime, now) {
|
|
626
671
|
const hoursUntilStart = startDateTime.diff(now, "hour", true);
|
|
627
672
|
if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
|
|
628
|
-
return
|
|
673
|
+
return EnumEventDateStatus2.STARTING_SOON;
|
|
629
674
|
}
|
|
630
675
|
if (startDateTime.isSame(now, "day")) {
|
|
631
|
-
return
|
|
676
|
+
return EnumEventDateStatus2.TODAY;
|
|
632
677
|
}
|
|
633
678
|
if (startDateTime.isSame(now.add(1, "day"), "day")) {
|
|
634
|
-
return
|
|
679
|
+
return EnumEventDateStatus2.TOMORROW;
|
|
635
680
|
}
|
|
636
681
|
if (startDateTime.isSame(now, "isoWeek")) {
|
|
637
|
-
return
|
|
682
|
+
return EnumEventDateStatus2.THIS_WEEK;
|
|
638
683
|
}
|
|
639
684
|
if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
|
|
640
|
-
return
|
|
685
|
+
return EnumEventDateStatus2.NEXT_WEEK;
|
|
641
686
|
}
|
|
642
|
-
return
|
|
687
|
+
return EnumEventDateStatus2.UPCOMING;
|
|
643
688
|
}
|
|
644
689
|
function updateSingleDateTimeStatus(dateTime, now = dayjs2()) {
|
|
645
690
|
const dateTimeFormat = `${dateFormat} ${timeFormat}`;
|
|
@@ -656,13 +701,13 @@ function updateSingleDateTimeStatus(dateTime, now = dayjs2()) {
|
|
|
656
701
|
if (!startDateTime.isValid() || !endDateTime.isValid()) {
|
|
657
702
|
return {
|
|
658
703
|
...dateTime,
|
|
659
|
-
dateStatus:
|
|
704
|
+
dateStatus: EnumEventDateStatus2.INVALID
|
|
660
705
|
};
|
|
661
706
|
}
|
|
662
707
|
if (endDateTime.isBefore(startDateTime)) {
|
|
663
708
|
return {
|
|
664
709
|
...dateTime,
|
|
665
|
-
dateStatus:
|
|
710
|
+
dateStatus: EnumEventDateStatus2.INVALID
|
|
666
711
|
};
|
|
667
712
|
}
|
|
668
713
|
let dateStatus;
|
|
@@ -670,10 +715,10 @@ function updateSingleDateTimeStatus(dateTime, now = dayjs2()) {
|
|
|
670
715
|
if (startDateTime.isAfter(now)) {
|
|
671
716
|
dateStatus = getFutureEventStatus(startDateTime, now);
|
|
672
717
|
} else {
|
|
673
|
-
dateStatus =
|
|
718
|
+
dateStatus = EnumEventDateStatus2.STARTED;
|
|
674
719
|
}
|
|
675
720
|
} else {
|
|
676
|
-
dateStatus =
|
|
721
|
+
dateStatus = EnumEventDateStatus2.ENDED;
|
|
677
722
|
}
|
|
678
723
|
return {
|
|
679
724
|
...dateTime,
|
|
@@ -729,6 +774,111 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
729
774
|
}
|
|
730
775
|
return updated;
|
|
731
776
|
}
|
|
777
|
+
var ARCHIVABLE_EVENT_FILTER = {
|
|
778
|
+
"dateTime.dateStatus": {
|
|
779
|
+
$in: [EnumEventDateStatus2.ENDED, EnumEventDateStatus2.INVALID]
|
|
780
|
+
},
|
|
781
|
+
deletedAt: null
|
|
782
|
+
};
|
|
783
|
+
async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
784
|
+
const cursor = EventModel.find(ARCHIVABLE_EVENT_FILTER).select({ _id: 1, dateTime: 1 }).lean().cursor({ batchSize: CURSOR_BATCH_SIZE });
|
|
785
|
+
let archivedCount = 0;
|
|
786
|
+
let archiveOps = [];
|
|
787
|
+
let eventOps = [];
|
|
788
|
+
const flushBulkWrites = async () => {
|
|
789
|
+
if (archiveOps.length) {
|
|
790
|
+
await EventDateArchiveModel.bulkWrite(archiveOps);
|
|
791
|
+
archiveOps = [];
|
|
792
|
+
}
|
|
793
|
+
if (eventOps.length) {
|
|
794
|
+
await EventModel.bulkWrite(eventOps);
|
|
795
|
+
eventOps = [];
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
try {
|
|
799
|
+
for await (const doc of cursor) {
|
|
800
|
+
const updated = doc.dateTime.map(
|
|
801
|
+
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
802
|
+
);
|
|
803
|
+
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
804
|
+
if (archive.length === 0 && discard.length === 0) {
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (archive.length > 0) {
|
|
808
|
+
const uniqueArchive = dedupeArchivedSlotsByStartDateTime(archive);
|
|
809
|
+
archiveOps.push({
|
|
810
|
+
updateOne: {
|
|
811
|
+
filter: { eventId: doc._id },
|
|
812
|
+
update: { $addToSet: { dateTime: { $each: uniqueArchive } } },
|
|
813
|
+
upsert: true
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
archivedCount += uniqueArchive.length;
|
|
817
|
+
}
|
|
818
|
+
eventOps.push({
|
|
819
|
+
updateOne: {
|
|
820
|
+
filter: { _id: doc._id },
|
|
821
|
+
update: {
|
|
822
|
+
$pull: {
|
|
823
|
+
dateTime: {
|
|
824
|
+
dateStatus: {
|
|
825
|
+
$in: [EnumEventDateStatus2.ENDED, EnumEventDateStatus2.INVALID]
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
if (archiveOps.length >= CURSOR_BATCH_SIZE || eventOps.length >= CURSOR_BATCH_SIZE) {
|
|
833
|
+
await flushBulkWrites();
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
await flushBulkWrites();
|
|
837
|
+
} finally {
|
|
838
|
+
await cursor.close().catch(() => void 0);
|
|
839
|
+
}
|
|
840
|
+
return archivedCount;
|
|
841
|
+
}
|
|
842
|
+
var EVENT_INFO_DATE_FILTER = {
|
|
843
|
+
dateTime: { $ne: [], $type: "array" }
|
|
844
|
+
};
|
|
845
|
+
async function cleanEventInfoDates(now) {
|
|
846
|
+
const cursor = EventInfoModel.find(EVENT_INFO_DATE_FILTER).select({ _id: 1, dateTime: 1 }).lean().cursor({ batchSize: CURSOR_BATCH_SIZE });
|
|
847
|
+
let removedCount = 0;
|
|
848
|
+
let bulkOps = [];
|
|
849
|
+
const flushBulkWrites = async () => {
|
|
850
|
+
if (!bulkOps.length) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
await EventInfoModel.bulkWrite(bulkOps);
|
|
854
|
+
bulkOps = [];
|
|
855
|
+
};
|
|
856
|
+
try {
|
|
857
|
+
for await (const doc of cursor) {
|
|
858
|
+
const updated = doc.dateTime.map(
|
|
859
|
+
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
860
|
+
);
|
|
861
|
+
const kept = filterDatesByFutureStatus(updated);
|
|
862
|
+
if (kept.length === updated.length) {
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
bulkOps.push({
|
|
866
|
+
updateOne: {
|
|
867
|
+
filter: { _id: doc._id },
|
|
868
|
+
update: { $set: { dateTime: kept } }
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
removedCount += updated.length - kept.length;
|
|
872
|
+
if (bulkOps.length >= CURSOR_BATCH_SIZE) {
|
|
873
|
+
await flushBulkWrites();
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
await flushBulkWrites();
|
|
877
|
+
} finally {
|
|
878
|
+
await cursor.close().catch(() => void 0);
|
|
879
|
+
}
|
|
880
|
+
return removedCount;
|
|
881
|
+
}
|
|
732
882
|
async function updateAllEventDateTimeStatuses() {
|
|
733
883
|
const now = dayjs2();
|
|
734
884
|
const [eventCount, marketCount] = await Promise.all([
|
|
@@ -741,6 +891,16 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
741
891
|
console.log(
|
|
742
892
|
`\u2705 Event dateTime statuses updated: events=${eventCount} changed, google imported markets=${marketCount} changed`
|
|
743
893
|
);
|
|
894
|
+
const archivedCount = await archiveEndedAndDiscardInvalidEventDates(now);
|
|
895
|
+
if (archivedCount > 0) {
|
|
896
|
+
console.log(`\u2705 Archived ${archivedCount} ended event date slot(s)`);
|
|
897
|
+
}
|
|
898
|
+
const removedEventInfoCount = await cleanEventInfoDates(now);
|
|
899
|
+
if (removedEventInfoCount > 0) {
|
|
900
|
+
console.log(
|
|
901
|
+
`\u2705 Removed ${removedEventInfoCount} non-future event info date slot(s)`
|
|
902
|
+
);
|
|
903
|
+
}
|
|
744
904
|
}
|
|
745
905
|
|
|
746
906
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
@@ -1915,6 +2075,7 @@ export {
|
|
|
1915
2075
|
connectToDatabase,
|
|
1916
2076
|
convertObjectIdsToStrings,
|
|
1917
2077
|
createLicenceObject,
|
|
2078
|
+
dedupeArchivedSlotsByStartDateTime,
|
|
1918
2079
|
didRemoveAnyEventDates,
|
|
1919
2080
|
downgradeVendorProFeatures,
|
|
1920
2081
|
ensureUserLicenseCompliance,
|
|
@@ -1945,6 +2106,7 @@ export {
|
|
|
1945
2106
|
normalizePromoCode,
|
|
1946
2107
|
notifyUsers,
|
|
1947
2108
|
partnerLicences,
|
|
2109
|
+
persistArchivedEventDates,
|
|
1948
2110
|
processLicenseReminder,
|
|
1949
2111
|
processUserCompliance,
|
|
1950
2112
|
processUserLicenseReminders,
|
|
@@ -1957,6 +2119,7 @@ export {
|
|
|
1957
2119
|
sendLicenseReminder,
|
|
1958
2120
|
sendPushNotifications,
|
|
1959
2121
|
sendReminderSafely,
|
|
2122
|
+
splitEventDatesForArchive,
|
|
1960
2123
|
syncUserLicencesAfterExpiry,
|
|
1961
2124
|
updateAdStatuses,
|
|
1962
2125
|
updateAllEventDateTimeStatuses,
|