@timardex/cluemart-server-shared 2.2.12 → 2.2.22

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.
@@ -2,8 +2,8 @@ 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
4
  export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
5
- import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-i11rkfv5.mjs';
6
- import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.mjs';
5
+ import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-6AEy-gNx.mjs';
6
+ import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-CmtBYjpi.mjs';
7
7
  import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
8
8
  import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
9
9
  import dayjs, { Dayjs } from 'dayjs';
@@ -2,8 +2,8 @@ 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
4
  export { updateSingleDateTimeStatus } from '@timardex/cluemart-shared';
5
- import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-BSF7Wm6O.js';
6
- import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-Bq-lT7a2.js';
5
+ import { d as SchemaAffiliateResourceType, S as SchemaOwnerType, g as SchemaRelationType, j as SchemaUserType } from '../Affiliate-D40kRxO_.js';
6
+ import { O as ObjectId, G as GraphQLContext, e as SchemaCreateBulkNotificationInput } from '../index-CmtBYjpi.js';
7
7
  import { DateTimeType as DateTimeType$1 } from '@timardex/cluemart-shared/types';
8
8
  import { EnumUserLicence } from '@timardex/cluemart-shared/enums';
9
9
  import dayjs, { Dayjs } from 'dayjs';
@@ -10,8 +10,8 @@ import {
10
10
  PushTokenModel,
11
11
  UserModel,
12
12
  VendorModel
13
- } from "../chunk-ZKHRT2PV.mjs";
14
- import "../chunk-6PNG5BI5.mjs";
13
+ } from "../chunk-TIGQ6F5T.mjs";
14
+ import "../chunk-TMPPPLIW.mjs";
15
15
 
16
16
  // src/service/promoCode/constants.ts
17
17
  var ACTIVE_NOT_DELETED_FILTER = {
@@ -617,10 +617,17 @@ import {
617
617
  filterDatesByFutureStatus,
618
618
  updateSingleDateTimeStatus
619
619
  } from "@timardex/cluemart-shared";
620
- import dayjs2 from "dayjs";
620
+ import dayjs3 from "dayjs";
621
621
 
622
622
  // src/service/event/archiveEndedEventDates.ts
623
- import { EnumEventDateStatus } from "@timardex/cluemart-shared";
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: [EnumEventDateStatus2.ENDED, EnumEventDateStatus2.INVALID]
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(eventOps);
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
- if (archive.length === 0 && discard.length === 0) {
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 = dayjs2();
856
+ const now = dayjs3();
819
857
  const [eventCount, marketCount] = await Promise.all([
820
858
  updateModelDateTimeStatuses(EventModel, now),
821
859
  updateModelDateTimeStatuses(
@@ -881,13 +919,13 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
881
919
  }
882
920
 
883
921
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
884
- import dayjs6 from "dayjs";
922
+ import dayjs7 from "dayjs";
885
923
 
886
924
  // src/service/license/compliance/utils.ts
887
925
  import {
888
926
  EnumUserLicence as EnumUserLicence7
889
927
  } from "@timardex/cluemart-shared";
890
- import dayjs5 from "dayjs";
928
+ import dayjs6 from "dayjs";
891
929
 
892
930
  // src/service/license/compliance/event.ts
893
931
  import { EnumUserLicence as EnumUserLicence3 } from "@timardex/cluemart-shared";
@@ -1125,7 +1163,7 @@ import {
1125
1163
  EnumUserLicence as EnumUserLicence6,
1126
1164
  vendorLicences
1127
1165
  } from "@timardex/cluemart-shared";
1128
- import dayjs4 from "dayjs";
1166
+ import dayjs5 from "dayjs";
1129
1167
 
1130
1168
  // src/service/license/models.ts
1131
1169
  import {
@@ -1134,7 +1172,7 @@ import {
1134
1172
  isNonVisitorResourceType,
1135
1173
  LicenceExpiryDate
1136
1174
  } from "@timardex/cluemart-shared";
1137
- import dayjs3 from "dayjs";
1175
+ import dayjs4 from "dayjs";
1138
1176
  import { GraphQLError } from "graphql";
1139
1177
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
1140
1178
  LicenceCategory2["EVENT"] = "event";
@@ -1215,7 +1253,7 @@ function getHighestLicenceForCategory(licences, category) {
1215
1253
  return highestLicence;
1216
1254
  }
1217
1255
  function createLicenceObject(expiryDate, licenceType) {
1218
- const today = dayjs3();
1256
+ const today = dayjs4();
1219
1257
  const expiryDateMapping = {
1220
1258
  [LicenceExpiryDate.ONE_YEAR]: today.add(1, "year").endOf("day").toDate(),
1221
1259
  [LicenceExpiryDate.ONE_MONTH]: today.add(1, "month").endOf("day").toDate(),
@@ -1478,7 +1516,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
1478
1516
  if (!stripe || stripe.currentPlan !== licenceType) {
1479
1517
  return false;
1480
1518
  }
1481
- const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs4(stripe.paymentGracePeriodEndsAt) : null;
1519
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs5(stripe.paymentGracePeriodEndsAt) : null;
1482
1520
  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
1521
  if (hasActivePaymentGracePeriod) {
1484
1522
  return true;
@@ -1492,7 +1530,7 @@ function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
1492
1530
  if (!stripe.endDate) {
1493
1531
  return false;
1494
1532
  }
1495
- const paidThrough = dayjs4(stripe.endDate);
1533
+ const paidThrough = dayjs5(stripe.endDate);
1496
1534
  return paidThrough.isValid() && paidThrough.isAfter(now);
1497
1535
  }
1498
1536
  async function handleVendorLicenceCompliance(user, now) {
@@ -1509,7 +1547,7 @@ async function handleVendorLicenceCompliance(user, now) {
1509
1547
  (licence) => licence.licenceType !== EnumUserLicence6.STANDARD_VENDOR
1510
1548
  );
1511
1549
  const expiredProLicences = proLicences.filter(
1512
- (licence) => !dayjs4(licence.expiryDate).isAfter(now)
1550
+ (licence) => !dayjs5(licence.expiryDate).isAfter(now)
1513
1551
  );
1514
1552
  const stripeProtectedLicenceTypes = new Set(
1515
1553
  expiredProLicences.filter(
@@ -1521,7 +1559,7 @@ async function handleVendorLicenceCompliance(user, now) {
1521
1559
  );
1522
1560
  const hasValidProLicence = stripeProtectedLicenceTypes.size > 0 || hasValidLicence(proLicences, vendorLicences, now);
1523
1561
  const hasExpiredVendorLicence = vendorLicencesOfUser.some(
1524
- (licence) => !dayjs4(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
1562
+ (licence) => !dayjs5(licence.expiryDate).isAfter(now) && !stripeProtectedLicenceTypes.has(licence.licenceType)
1525
1563
  );
1526
1564
  if (!hasExpiredVendorLicence) {
1527
1565
  return;
@@ -1575,9 +1613,9 @@ async function vendorOwnerHasProLicence(vendorId) {
1575
1613
  if (!owner) {
1576
1614
  return false;
1577
1615
  }
1578
- const now = dayjs4();
1616
+ const now = dayjs5();
1579
1617
  const effectiveVendorLicences = owner.licences?.filter(
1580
- (licence) => licence?.licenceType && (dayjs4(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
1618
+ (licence) => licence?.licenceType && (dayjs5(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
1581
1619
  owner,
1582
1620
  licence.licenceType,
1583
1621
  now
@@ -1614,7 +1652,7 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
1614
1652
  }
1615
1653
  function hasValidLicence(licences, licenceTypes, now) {
1616
1654
  return licences.some(
1617
- (licence) => licenceTypes.includes(licence.licenceType) && dayjs5(licence.expiryDate).isAfter(now)
1655
+ (licence) => licenceTypes.includes(licence.licenceType) && dayjs6(licence.expiryDate).isAfter(now)
1618
1656
  );
1619
1657
  }
1620
1658
  async function sendDeactivationNotification(payload, userId, resourceName, resourceType) {
@@ -1641,7 +1679,7 @@ async function processUserCompliance(user, now) {
1641
1679
  }
1642
1680
 
1643
1681
  // src/service/license/compliance/ensureUserLicenseCompliance.ts
1644
- async function ensureUserLicenseComplianceForUser(userId, now = dayjs6()) {
1682
+ async function ensureUserLicenseComplianceForUser(userId, now = dayjs7()) {
1645
1683
  const user = await UserModel.findById(userId);
1646
1684
  if (!user) {
1647
1685
  return;
@@ -1649,7 +1687,7 @@ async function ensureUserLicenseComplianceForUser(userId, now = dayjs6()) {
1649
1687
  await processUserCompliance(user, now);
1650
1688
  }
1651
1689
  async function ensureUserLicenseCompliance() {
1652
- const now = dayjs6();
1690
+ const now = dayjs7();
1653
1691
  console.log(`\u{1F50D} Checking license compliance at ${now.format()}`);
1654
1692
  const nowDate = now.toDate();
1655
1693
  const users = await UserModel.find({
@@ -1724,7 +1762,7 @@ async function getPartnerResourceInfo(userId, partnerId) {
1724
1762
  }
1725
1763
 
1726
1764
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
1727
- import dayjs8 from "dayjs";
1765
+ import dayjs9 from "dayjs";
1728
1766
 
1729
1767
  // src/service/license/reminder/reminderWindow.ts
1730
1768
  var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
@@ -1732,7 +1770,7 @@ var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
1732
1770
 
1733
1771
  // src/service/license/reminder/utils.ts
1734
1772
  import {
1735
- dateFormat,
1773
+ dateFormat as dateFormat2,
1736
1774
  EnumNotificationResourceType as EnumNotificationResourceType4,
1737
1775
  EnumNotificationType as EnumNotificationType4,
1738
1776
  EnumUserLicence as EnumUserLicence8,
@@ -1740,7 +1778,7 @@ import {
1740
1778
  vendorLicences as vendorLicences2
1741
1779
  } from "@timardex/cluemart-shared";
1742
1780
  import { formatDate } from "@timardex/cluemart-shared/utils";
1743
- import dayjs7 from "dayjs";
1781
+ import dayjs8 from "dayjs";
1744
1782
 
1745
1783
  // src/service/license/reminder/vendor.ts
1746
1784
  async function getVendorResourceInfo(userId, vendorId) {
@@ -1799,7 +1837,7 @@ async function checkAndCreateNotification(payload) {
1799
1837
  }
1800
1838
  }
1801
1839
  function isLicenseExpiringIn7Days(expiryDate, now) {
1802
- const expiry = dayjs7(expiryDate);
1840
+ const expiry = dayjs8(expiryDate);
1803
1841
  const hoursUntilExpiry = expiry.diff(now, "hour", true);
1804
1842
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
1805
1843
  }
@@ -1877,7 +1915,7 @@ function getLicenceExpiryMode(licenceType) {
1877
1915
  }
1878
1916
  async function sendLicenseReminder(user, licence) {
1879
1917
  const licenceName = getLicenseName(licence.licenceType);
1880
- const expiryDate = dayjs7(licence.expiryDate).format(dateFormat);
1918
+ const expiryDate = dayjs8(licence.expiryDate).format(dateFormat2);
1881
1919
  const userId = String(user._id);
1882
1920
  const resourceInfo = await getLicenseResourceInfo(user, licence);
1883
1921
  if (!resourceInfo) {
@@ -1909,7 +1947,7 @@ async function sendLicenseReminder(user, licence) {
1909
1947
  console.log(`\u2705 Sent 7-day reminder to user ${userId} for ${licenceName}`);
1910
1948
  }
1911
1949
  async function processLicenseReminder(licence, now) {
1912
- if (dayjs7(licence.expiryDate).isBefore(now)) {
1950
+ if (dayjs8(licence.expiryDate).isBefore(now)) {
1913
1951
  return false;
1914
1952
  }
1915
1953
  if (!isLicenseExpiringIn7Days(licence.expiryDate, now)) {
@@ -1963,7 +2001,7 @@ async function processUserLicenseReminders(user, now) {
1963
2001
 
1964
2002
  // src/service/license/reminder/remindUsersAboutLicenseExpiration.ts
1965
2003
  async function remindUsersAboutLicenseExpiration() {
1966
- const now = dayjs8();
2004
+ const now = dayjs9();
1967
2005
  console.log(`\u{1F50D} Checking for licenses expiring in 7 days at ${now.format()}`);
1968
2006
  const minExpiryDate = now.add(REMINDER_WINDOW_MIN_HOURS, "hour").toDate();
1969
2007
  const maxExpiryDate = now.add(REMINDER_WINDOW_MAX_HOURS, "hour").toDate();