@timardex/cluemart-server-shared 2.1.0 → 2.1.2

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.
@@ -129,9 +129,30 @@ var schemaAdresource = new MongooseSchema({
129
129
  var schema = new MongooseSchema(
130
130
  {
131
131
  active: { default: true, type: Boolean },
132
+ adminManaged: { default: false, type: Boolean },
133
+ approvalStatus: {
134
+ enum: Object.values(import_cluemart_shared.EnumAdApprovalStatus),
135
+ required: false,
136
+ type: String
137
+ },
138
+ bookingIds: {
139
+ default: void 0,
140
+ ref: "AdBooking",
141
+ type: [import_mongoose.default.Schema.Types.ObjectId]
142
+ },
143
+ bookingKind: {
144
+ enum: Object.values(import_cluemart_shared.EnumAdBookingSlotKind),
145
+ required: false,
146
+ type: String
147
+ },
132
148
  clicks: { default: 0, required: true, type: Number },
133
149
  end: { required: true, type: Date },
134
150
  impressions: { default: 0, required: true, type: Number },
151
+ paymentStatus: {
152
+ enum: Object.values(import_cluemart_shared.EnumAdPaymentStatus),
153
+ required: false,
154
+ type: String
155
+ },
135
156
  resource: { required: true, type: schemaAdresource },
136
157
  showOn: {
137
158
  default: [import_cluemart_shared.EnumAdShowOn.FRONT_PAGE],
@@ -163,20 +184,274 @@ schema.index({
163
184
  // eslint-disable-next-line sort-keys
164
185
  start: -1
165
186
  });
187
+ schema.index(
188
+ { bookingIds: 1 },
189
+ {
190
+ partialFilterExpression: { bookingIds: { $exists: true } },
191
+ unique: true
192
+ }
193
+ );
166
194
  var AdModel = import_mongoose.default.models.Ad || import_mongoose.default.model("Ad", schema);
167
195
 
168
- // src/mongoose/BillingCatalog.ts
169
- var import_cluemart_shared2 = require("@timardex/cluemart-shared");
196
+ // src/mongoose/AdBillingCatalog.ts
170
197
  var import_mongoose2 = __toESM(require("mongoose"));
171
- var MongooseSchema2 = import_mongoose2.default.Schema;
198
+ var AD_BILLING_CATALOG_COLLECTION_NAME = "adBillingCatalog";
199
+ var schema2 = new import_mongoose2.default.Schema(
200
+ {
201
+ active: { default: true, required: true, type: Boolean },
202
+ currency: {
203
+ default: "nzd",
204
+ enum: ["nzd"],
205
+ immutable: true,
206
+ required: true,
207
+ type: String
208
+ },
209
+ key: {
210
+ enum: ["front_page_day", "market_search_day"],
211
+ immutable: true,
212
+ required: true,
213
+ type: String,
214
+ unique: true
215
+ },
216
+ revision: { default: 1, min: 1, required: true, type: Number },
217
+ unitAmount: {
218
+ min: 1,
219
+ required: true,
220
+ type: Number,
221
+ validate: {
222
+ message: "Daily ad price must be a positive integer amount of cents.",
223
+ validator: Number.isInteger
224
+ }
225
+ }
226
+ },
227
+ { collection: AD_BILLING_CATALOG_COLLECTION_NAME, timestamps: true }
228
+ );
229
+ var AdBillingCatalogModel = import_mongoose2.default.models.AdBillingCatalog || import_mongoose2.default.model(
230
+ "AdBillingCatalog",
231
+ schema2,
232
+ AD_BILLING_CATALOG_COLLECTION_NAME
233
+ );
234
+
235
+ // src/mongoose/AdBooking.ts
236
+ var import_cluemart_shared2 = require("@timardex/cluemart-shared");
237
+ var import_mongoose3 = __toESM(require("mongoose"));
238
+ var liveStates = [
239
+ import_cluemart_shared2.EnumAdBookingState.HELD,
240
+ import_cluemart_shared2.EnumAdBookingState.PENDING_APPROVAL,
241
+ import_cluemart_shared2.EnumAdBookingState.APPROVED
242
+ ];
243
+ var placementValues = [import_cluemart_shared2.EnumAdShowOn.FRONT_PAGE, import_cluemart_shared2.EnumAdShowOn.MARKET_SEARCH];
244
+ var schema3 = new import_mongoose3.default.Schema(
245
+ {
246
+ adId: { default: null, ref: "Ad", type: String },
247
+ approvalStatus: {
248
+ default: import_cluemart_shared2.EnumAdApprovalStatus.PENDING,
249
+ enum: Object.values(import_cluemart_shared2.EnumAdApprovalStatus),
250
+ required: true,
251
+ type: String
252
+ },
253
+ checkoutAttemptId: { default: null, type: String },
254
+ currency: { default: null, lowercase: true, type: String },
255
+ dayKey: {
256
+ immutable: true,
257
+ match: /^\d{4}-\d{2}-\d{2}$/,
258
+ required: true,
259
+ type: String
260
+ },
261
+ entitlementClaimKey: { default: null, type: String },
262
+ entitlementSource: {
263
+ default: null,
264
+ enum: Object.values(import_cluemart_shared2.EnumAdEntitlementSource),
265
+ type: String
266
+ },
267
+ expiresAt: { default: null, type: Date },
268
+ placement: {
269
+ enum: placementValues,
270
+ immutable: true,
271
+ required: true,
272
+ type: String
273
+ },
274
+ purchaseKey: { default: null, immutable: true, type: String },
275
+ region: {
276
+ immutable: true,
277
+ lowercase: true,
278
+ required: true,
279
+ trim: true,
280
+ type: String
281
+ },
282
+ resource: { required: true, type: schemaAdresource },
283
+ slotKind: {
284
+ enum: Object.values(import_cluemart_shared2.EnumAdBookingSlotKind),
285
+ immutable: true,
286
+ required: true,
287
+ type: String
288
+ },
289
+ slotNumber: { immutable: true, min: 1, required: true, type: Number },
290
+ state: {
291
+ default: import_cluemart_shared2.EnumAdBookingState.HELD,
292
+ enum: Object.values(import_cluemart_shared2.EnumAdBookingState),
293
+ required: true,
294
+ type: String
295
+ },
296
+ stripeCheckoutSessionId: { default: null, type: String },
297
+ stripePaymentIntentId: { default: null, type: String },
298
+ unitAmount: { default: null, min: 1, type: Number },
299
+ userId: { immutable: true, ref: "User", required: true, type: String }
300
+ },
301
+ { timestamps: true }
302
+ );
303
+ schema3.pre(
304
+ "validate",
305
+ function validateSlot() {
306
+ if (!Number.isInteger(this.slotNumber)) {
307
+ this.invalidate("slotNumber", "Ad booking slot must be an integer.");
308
+ return;
309
+ }
310
+ const maximum = this.slotKind === import_cluemart_shared2.EnumAdBookingSlotKind.PAID ? 30 : 7;
311
+ if (this.slotNumber < 1 || this.slotNumber > maximum) {
312
+ this.invalidate(
313
+ "slotNumber",
314
+ `Ad booking slot must be between 1 and ${maximum}.`
315
+ );
316
+ }
317
+ if (this.slotKind === import_cluemart_shared2.EnumAdBookingSlotKind.PAID && this.state !== import_cluemart_shared2.EnumAdBookingState.HELD && this.state !== import_cluemart_shared2.EnumAdBookingState.FAILED && this.state !== import_cluemart_shared2.EnumAdBookingState.CANCELLED && (!this.unitAmount || !this.currency)) {
318
+ this.invalidate(
319
+ "unitAmount",
320
+ "Paid ad booking must retain its checkout price."
321
+ );
322
+ }
323
+ }
324
+ );
325
+ schema3.index(
326
+ { region: 1, placement: 1, dayKey: 1, slotKind: 1, slotNumber: 1 },
327
+ { unique: true, partialFilterExpression: { state: { $in: liveStates } } }
328
+ );
329
+ schema3.index({ userId: 1, dayKey: -1 });
330
+ schema3.index(
331
+ { checkoutAttemptId: 1 },
332
+ {
333
+ partialFilterExpression: { checkoutAttemptId: { $type: "string" } },
334
+ unique: true
335
+ }
336
+ );
337
+ schema3.index(
338
+ { purchaseKey: 1 },
339
+ {
340
+ partialFilterExpression: {
341
+ purchaseKey: { $type: "string" },
342
+ state: { $in: liveStates }
343
+ },
344
+ unique: true
345
+ }
346
+ );
347
+ schema3.index(
348
+ { entitlementClaimKey: 1 },
349
+ {
350
+ partialFilterExpression: {
351
+ entitlementClaimKey: { $type: "string" },
352
+ state: { $in: liveStates }
353
+ },
354
+ unique: true
355
+ }
356
+ );
357
+ schema3.index(
358
+ { adId: 1, region: 1, placement: 1, dayKey: 1 },
359
+ {
360
+ partialFilterExpression: {
361
+ entitlementSource: import_cluemart_shared2.EnumAdEntitlementSource.ADMIN,
362
+ state: { $in: liveStates }
363
+ },
364
+ unique: true
365
+ }
366
+ );
367
+ schema3.index(
368
+ { stripeCheckoutSessionId: 1 },
369
+ {
370
+ partialFilterExpression: { stripeCheckoutSessionId: { $type: "string" } },
371
+ unique: true
372
+ }
373
+ );
374
+ var AdBookingModel = import_mongoose3.default.models.AdBooking || import_mongoose3.default.model("AdBooking", schema3);
375
+
376
+ // src/mongoose/AdImpression.ts
377
+ var import_cluemart_shared3 = require("@timardex/cluemart-shared");
378
+ var import_mongoose4 = __toESM(require("mongoose"));
379
+ var schema4 = new import_mongoose4.default.Schema(
380
+ {
381
+ _id: { required: true, type: String },
382
+ adId: { required: true, type: String },
383
+ dayKey: { match: /^\d{4}-\d{2}-\d{2}$/, required: true, type: String },
384
+ placement: {
385
+ enum: [import_cluemart_shared3.EnumAdShowOn.FRONT_PAGE, import_cluemart_shared3.EnumAdShowOn.MARKET_SEARCH],
386
+ required: true,
387
+ type: String
388
+ },
389
+ recordedAt: { default: Date.now, required: true, type: Date },
390
+ viewerSlotKey: { required: true, type: String }
391
+ },
392
+ { collection: "adImpressions" }
393
+ );
394
+ schema4.index({ adId: 1, recordedAt: 1 });
395
+ schema4.index({ adId: 1, placement: 1, viewerSlotKey: 1 }, { unique: true });
396
+ schema4.index({ recordedAt: 1 }, { expireAfterSeconds: 7 * 24 * 60 * 60 });
397
+ schema4.index({ dayKey: 1, placement: 1, adId: 1 });
398
+ var AdImpressionModel = import_mongoose4.default.models.AdImpression || import_mongoose4.default.model("AdImpression", schema4, "adImpressions");
399
+
400
+ // src/mongoose/AdSettings.ts
401
+ var import_mongoose5 = __toESM(require("mongoose"));
402
+ var schema5 = new import_mongoose5.default.Schema(
403
+ {
404
+ _id: { default: "default", enum: ["default"], type: String },
405
+ approvalRequired: { default: true, required: true, type: Boolean },
406
+ minAppearancesPerHour: {
407
+ default: 12,
408
+ min: 1,
409
+ required: true,
410
+ type: Number,
411
+ validate: {
412
+ message: "Minimum appearances per hour must be a whole number.",
413
+ validator: Number.isInteger
414
+ }
415
+ },
416
+ paidSlotsPerPlacement: {
417
+ default: 30,
418
+ enum: [30],
419
+ immutable: true,
420
+ type: Number
421
+ },
422
+ reservedSlotsPerPlacement: {
423
+ default: 7,
424
+ enum: [7],
425
+ immutable: true,
426
+ type: Number
427
+ },
428
+ rotationSeconds: { default: 8, enum: [8], immutable: true, type: Number }
429
+ },
430
+ { collection: "adSettings", timestamps: true }
431
+ );
432
+ schema5.pre("validate", function validateRotationCapacity() {
433
+ const availableRotationsPerHour = 3600 / this.rotationSeconds;
434
+ if (this.minAppearancesPerHour * (this.paidSlotsPerPlacement + this.reservedSlotsPerPlacement) > availableRotationsPerHour) {
435
+ this.invalidate(
436
+ "minAppearancesPerHour",
437
+ "The configured minimum exceeds the available rotation slots."
438
+ );
439
+ }
440
+ });
441
+ var AdSettingsModel = import_mongoose5.default.models.AdSettings || import_mongoose5.default.model("AdSettings", schema5, "adSettings");
442
+
443
+ // src/mongoose/BillingCatalog.ts
444
+ var import_cluemart_shared4 = require("@timardex/cluemart-shared");
445
+ var import_mongoose6 = __toESM(require("mongoose"));
446
+ var MongooseSchema2 = import_mongoose6.default.Schema;
172
447
  var BILLING_CATALOG_COLLECTION_NAME = "billingCatalog";
173
448
  var paidVendorLicences = [
174
- import_cluemart_shared2.EnumUserLicence.PRO_VENDOR,
175
- import_cluemart_shared2.EnumUserLicence.PRO_PLUS_VENDOR
449
+ import_cluemart_shared4.EnumUserLicence.PRO_VENDOR,
450
+ import_cluemart_shared4.EnumUserLicence.PRO_PLUS_VENDOR
176
451
  ];
177
452
  var supportedBillingPeriods = [
178
- import_cluemart_shared2.EnumBillingPeriod.MONTHLY_CANCEL_ANYTIME,
179
- import_cluemart_shared2.EnumBillingPeriod.YEARLY_ANNUAL_BILLED
453
+ import_cluemart_shared4.EnumBillingPeriod.MONTHLY_CANCEL_ANYTIME,
454
+ import_cluemart_shared4.EnumBillingPeriod.YEARLY_ANNUAL_BILLED
180
455
  ];
181
456
  var unitAmountField = {
182
457
  min: 1,
@@ -188,8 +463,8 @@ var unitAmountField = {
188
463
  }
189
464
  };
190
465
  var currencyField = {
191
- default: import_cluemart_shared2.BILLING_CATALOG_CURRENCY,
192
- enum: [import_cluemart_shared2.BILLING_CATALOG_CURRENCY],
466
+ default: import_cluemart_shared4.BILLING_CATALOG_CURRENCY,
467
+ enum: [import_cluemart_shared4.BILLING_CATALOG_CURRENCY],
193
468
  immutable: true,
194
469
  lowercase: true,
195
470
  required: true,
@@ -215,7 +490,7 @@ var priceHistorySchema = new MongooseSchema2(
215
490
  default: null,
216
491
  ref: "User",
217
492
  required: false,
218
- type: import_mongoose2.default.Schema.Types.ObjectId
493
+ type: import_mongoose6.default.Schema.Types.ObjectId
219
494
  },
220
495
  currency: currencyField,
221
496
  effectiveFrom: { required: true, type: Date },
@@ -226,7 +501,7 @@ var priceHistorySchema = new MongooseSchema2(
226
501
  },
227
502
  { _id: false }
228
503
  );
229
- var schema2 = new MongooseSchema2(
504
+ var schema6 = new MongooseSchema2(
230
505
  {
231
506
  active: { default: true, required: true, type: Boolean },
232
507
  billingPeriod: {
@@ -238,7 +513,7 @@ var schema2 = new MongooseSchema2(
238
513
  currency: currencyField,
239
514
  effectiveFrom: { default: Date.now, required: true, type: Date },
240
515
  key: {
241
- enum: import_cluemart_shared2.BILLING_CATALOG_KEYS,
516
+ enum: import_cluemart_shared4.BILLING_CATALOG_KEYS,
242
517
  immutable: true,
243
518
  required: true,
244
519
  type: String,
@@ -282,7 +557,7 @@ var schema2 = new MongooseSchema2(
282
557
  default: null,
283
558
  ref: "User",
284
559
  required: false,
285
- type: import_mongoose2.default.Schema.Types.ObjectId
560
+ type: import_mongoose6.default.Schema.Types.ObjectId
286
561
  }
287
562
  },
288
563
  {
@@ -291,40 +566,40 @@ var schema2 = new MongooseSchema2(
291
566
  timestamps: true
292
567
  }
293
568
  );
294
- schema2.pre("validate", function validateDefinition() {
295
- if (!(0, import_cluemart_shared2.billingCatalogDefinitionMatches)(this)) {
569
+ schema6.pre("validate", function validateDefinition() {
570
+ if (!(0, import_cluemart_shared4.billingCatalogDefinitionMatches)(this)) {
296
571
  this.invalidate(
297
572
  "key",
298
573
  "Billing catalogue key does not match its licence and billing period."
299
574
  );
300
575
  }
301
576
  });
302
- schema2.index({ billingPeriod: 1, licenceType: 1 }, { unique: true });
303
- schema2.index({ active: 1, licenceType: 1 });
304
- schema2.index(
577
+ schema6.index({ billingPeriod: 1, licenceType: 1 }, { unique: true });
578
+ schema6.index({ active: 1, licenceType: 1 });
579
+ schema6.index(
305
580
  { stripePriceId: 1 },
306
581
  {
307
582
  partialFilterExpression: { stripePriceId: { $type: "string" } },
308
583
  unique: true
309
584
  }
310
585
  );
311
- var BillingCatalogModel = import_mongoose2.default.models.BillingCatalogEntry || import_mongoose2.default.model(
586
+ var BillingCatalogModel = import_mongoose6.default.models.BillingCatalogEntry || import_mongoose6.default.model(
312
587
  "BillingCatalogEntry",
313
- schema2,
588
+ schema6,
314
589
  BILLING_CATALOG_COLLECTION_NAME
315
590
  );
316
591
 
317
592
  // src/mongoose/chat/Chat.ts
318
- var import_cluemart_shared3 = require("@timardex/cluemart-shared");
319
- var import_mongoose3 = __toESM(require("mongoose"));
320
- var MongooseSchema3 = import_mongoose3.default.Schema;
593
+ var import_cluemart_shared5 = require("@timardex/cluemart-shared");
594
+ var import_mongoose7 = __toESM(require("mongoose"));
595
+ var MongooseSchema3 = import_mongoose7.default.Schema;
321
596
  var MessageReplyPreviewSchema = new MongooseSchema3(
322
597
  {
323
598
  contentPreview: { required: true, type: String },
324
599
  senderId: {
325
600
  ref: "User",
326
601
  required: true,
327
- type: import_mongoose3.default.Schema.Types.ObjectId
602
+ type: import_mongoose7.default.Schema.Types.ObjectId
328
603
  },
329
604
  senderName: { required: true, type: String }
330
605
  },
@@ -336,7 +611,7 @@ var MessageReactionSchema = new MongooseSchema3(
336
611
  userId: {
337
612
  ref: "User",
338
613
  required: true,
339
- type: import_mongoose3.default.Schema.Types.ObjectId
614
+ type: import_mongoose7.default.Schema.Types.ObjectId
340
615
  }
341
616
  },
342
617
  { _id: false }
@@ -347,7 +622,7 @@ var MessageSeenSchema = new MongooseSchema3(
347
622
  userId: {
348
623
  ref: "User",
349
624
  required: true,
350
- type: import_mongoose3.default.Schema.Types.ObjectId
625
+ type: import_mongoose7.default.Schema.Types.ObjectId
351
626
  }
352
627
  },
353
628
  { _id: false }
@@ -363,13 +638,13 @@ var MessageSchema = new MongooseSchema3(
363
638
  replyToMessageId: {
364
639
  ref: "Chat.messages",
365
640
  required: false,
366
- type: import_mongoose3.default.Schema.Types.ObjectId
641
+ type: import_mongoose7.default.Schema.Types.ObjectId
367
642
  },
368
643
  seenBy: { default: [], required: false, type: [MessageSeenSchema] },
369
644
  senderId: {
370
645
  ref: "User",
371
646
  required: true,
372
- type: import_mongoose3.default.Schema.Types.ObjectId
647
+ type: import_mongoose7.default.Schema.Types.ObjectId
373
648
  }
374
649
  },
375
650
  { timestamps: true }
@@ -382,7 +657,7 @@ var ParticipantSchema = new MongooseSchema3(
382
657
  userId: {
383
658
  ref: "User",
384
659
  required: true,
385
- type: import_mongoose3.default.Schema.Types.ObjectId
660
+ type: import_mongoose7.default.Schema.Types.ObjectId
386
661
  },
387
662
  userName: { required: true, type: String }
388
663
  },
@@ -395,7 +670,7 @@ var ChatSchema = new MongooseSchema3(
395
670
  chatDescription: { required: false, type: String },
396
671
  chatName: { required: true, type: String },
397
672
  chatType: {
398
- enum: Object.values(import_cluemart_shared3.EnumChatType),
673
+ enum: Object.values(import_cluemart_shared5.EnumChatType),
399
674
  required: true,
400
675
  type: String
401
676
  },
@@ -413,17 +688,17 @@ ChatSchema.index({
413
688
  "participants.userId": 1,
414
689
  updatedAt: -1
415
690
  });
416
- var ChatModel = import_mongoose3.default.models.Chat || import_mongoose3.default.model("Chat", ChatSchema);
691
+ var ChatModel = import_mongoose7.default.models.Chat || import_mongoose7.default.model("Chat", ChatSchema);
417
692
 
418
693
  // src/mongoose/chat/ChatReport.ts
419
- var import_cluemart_shared4 = require("@timardex/cluemart-shared");
420
- var import_mongoose4 = __toESM(require("mongoose"));
421
- var MongooseSchema4 = import_mongoose4.default.Schema;
694
+ var import_cluemart_shared6 = require("@timardex/cluemart-shared");
695
+ var import_mongoose8 = __toESM(require("mongoose"));
696
+ var MongooseSchema4 = import_mongoose8.default.Schema;
422
697
  var ReasonSchema = new MongooseSchema4(
423
698
  {
424
699
  details: { default: null, required: false, type: String },
425
700
  reasonType: {
426
- enum: Object.values(import_cluemart_shared4.EnumChatReportReason),
701
+ enum: Object.values(import_cluemart_shared6.EnumChatReportReason),
427
702
  required: true,
428
703
  type: String
429
704
  }
@@ -435,18 +710,18 @@ var ChatReportSchema = new MongooseSchema4(
435
710
  chatId: {
436
711
  ref: "Chat",
437
712
  required: true,
438
- type: import_mongoose4.default.Schema.Types.ObjectId
713
+ type: import_mongoose8.default.Schema.Types.ObjectId
439
714
  },
440
715
  reason: { required: true, type: ReasonSchema },
441
716
  reportedUserId: {
442
717
  ref: "User",
443
718
  required: true,
444
- type: import_mongoose4.default.Schema.Types.ObjectId
719
+ type: import_mongoose8.default.Schema.Types.ObjectId
445
720
  },
446
721
  reporterUserId: {
447
722
  ref: "User",
448
723
  required: true,
449
- type: import_mongoose4.default.Schema.Types.ObjectId
724
+ type: import_mongoose8.default.Schema.Types.ObjectId
450
725
  },
451
726
  resolved: { default: false, required: true, type: Boolean }
452
727
  },
@@ -454,20 +729,20 @@ var ChatReportSchema = new MongooseSchema4(
454
729
  );
455
730
  ChatReportSchema.index({ chatId: 1, reportedUserId: 1 });
456
731
  ChatReportSchema.index({ createdAt: -1, reporterUserId: 1 });
457
- var ChatReportModel = import_mongoose4.default.models.ChatReport || import_mongoose4.default.model("ChatReport", ChatReportSchema);
732
+ var ChatReportModel = import_mongoose8.default.models.ChatReport || import_mongoose8.default.model("ChatReport", ChatReportSchema);
458
733
 
459
734
  // src/mongoose/global.ts
460
- var import_cluemart_shared7 = require("@timardex/cluemart-shared");
461
- var import_mongoose7 = __toESM(require("mongoose"));
735
+ var import_cluemart_shared9 = require("@timardex/cluemart-shared");
736
+ var import_mongoose11 = __toESM(require("mongoose"));
462
737
 
463
738
  // src/mongoose/Relation.ts
464
- var import_cluemart_shared6 = require("@timardex/cluemart-shared");
465
- var import_mongoose6 = __toESM(require("mongoose"));
739
+ var import_cluemart_shared8 = require("@timardex/cluemart-shared");
740
+ var import_mongoose10 = __toESM(require("mongoose"));
466
741
 
467
742
  // src/mongoose/event/EventInfo.ts
468
- var import_cluemart_shared5 = require("@timardex/cluemart-shared");
469
- var import_mongoose5 = __toESM(require("mongoose"));
470
- var MongooseSchema5 = import_mongoose5.default.Schema;
743
+ var import_cluemart_shared7 = require("@timardex/cluemart-shared");
744
+ var import_mongoose9 = __toESM(require("mongoose"));
745
+ var MongooseSchema5 = import_mongoose9.default.Schema;
471
746
  var StallTypeSchema = new MongooseSchema5(
472
747
  {
473
748
  label: { required: false, type: String },
@@ -482,7 +757,7 @@ var StallTypeSchema = new MongooseSchema5(
482
757
  var dateTimeSchema = new MongooseSchema5(
483
758
  {
484
759
  dateStatus: {
485
- enum: Object.values(import_cluemart_shared5.EnumEventDateStatus),
760
+ enum: Object.values(import_cluemart_shared7.EnumEventDateStatus),
486
761
  required: false,
487
762
  type: String
488
763
  },
@@ -501,7 +776,7 @@ var paymentInfoSchema = new MongooseSchema5(
501
776
  accountNumber: { required: false, type: String },
502
777
  link: { required: false, type: String },
503
778
  paymentMethod: {
504
- enum: Object.values(import_cluemart_shared5.EnumPaymentMethod),
779
+ enum: Object.values(import_cluemart_shared7.EnumPaymentMethod),
505
780
  required: true,
506
781
  type: String
507
782
  }
@@ -528,7 +803,7 @@ var refundPolicySchema = new MongooseSchema5(
528
803
  },
529
804
  { _id: false }
530
805
  );
531
- var schema3 = new MongooseSchema5(
806
+ var schema7 = new MongooseSchema5(
532
807
  {
533
808
  active: { default: true, type: Boolean },
534
809
  applicationDeadlineHours: { required: true, type: Number },
@@ -536,7 +811,7 @@ var schema3 = new MongooseSchema5(
536
811
  eventId: {
537
812
  ref: "Event",
538
813
  required: true,
539
- type: import_mongoose5.default.Schema.Types.ObjectId
814
+ type: import_mongoose9.default.Schema.Types.ObjectId
540
815
  },
541
816
  packInTime: { required: true, type: Number },
542
817
  paymentDueHours: { required: true, type: Number },
@@ -546,15 +821,15 @@ var schema3 = new MongooseSchema5(
546
821
  },
547
822
  { timestamps: true }
548
823
  );
549
- schema3.index({ eventId: 1 });
550
- var EventInfoModel = import_mongoose5.default.models.EventInfo || import_mongoose5.default.model("EventInfo", schema3);
824
+ schema7.index({ eventId: 1 });
825
+ var EventInfoModel = import_mongoose9.default.models.EventInfo || import_mongoose9.default.model("EventInfo", schema7);
551
826
 
552
827
  // src/mongoose/Relation.ts
553
- var MongooseSchema6 = import_mongoose6.default.Schema;
828
+ var MongooseSchema6 = import_mongoose10.default.Schema;
554
829
  var relationDateTimeSchema = new MongooseSchema6(
555
830
  {
556
831
  dateStatus: {
557
- enum: Object.values(import_cluemart_shared6.EnumEventDateStatus),
832
+ enum: Object.values(import_cluemart_shared8.EnumEventDateStatus),
558
833
  required: true,
559
834
  type: String
560
835
  },
@@ -578,7 +853,7 @@ var relationDatesSchema = new MongooseSchema6(
578
853
  },
579
854
  paymentReference: { required: false, type: String },
580
855
  status: {
581
- enum: Object.values(import_cluemart_shared6.EnumInviteStatus),
856
+ enum: Object.values(import_cluemart_shared8.EnumInviteStatus),
582
857
  required: false,
583
858
  type: String
584
859
  }
@@ -591,29 +866,29 @@ var RelationTypeSchema = new MongooseSchema6(
591
866
  chatId: {
592
867
  ref: "Chat",
593
868
  required: true,
594
- type: import_mongoose6.default.Schema.Types.ObjectId
869
+ type: import_mongoose10.default.Schema.Types.ObjectId
595
870
  },
596
871
  deletedAt: { default: null, required: false, type: Date },
597
872
  eventId: {
598
873
  ref: "Event",
599
874
  required: true,
600
- type: import_mongoose6.default.Schema.Types.ObjectId
875
+ type: import_mongoose10.default.Schema.Types.ObjectId
601
876
  },
602
877
  lastUpdateBy: {
603
- enum: Object.values(import_cluemart_shared6.EnumResourceType),
878
+ enum: Object.values(import_cluemart_shared8.EnumResourceType),
604
879
  required: true,
605
880
  type: String
606
881
  },
607
882
  relationDates: [relationDatesSchema],
608
883
  relationType: {
609
- enum: Object.values(import_cluemart_shared6.EnumRelationResource),
884
+ enum: Object.values(import_cluemart_shared8.EnumRelationResource),
610
885
  required: true,
611
886
  type: String
612
887
  },
613
888
  vendorId: {
614
889
  ref: "Vendor",
615
890
  required: true,
616
- type: import_mongoose6.default.Schema.Types.ObjectId
891
+ type: import_mongoose10.default.Schema.Types.ObjectId
617
892
  }
618
893
  },
619
894
  { timestamps: true }
@@ -625,17 +900,17 @@ RelationTypeSchema.index({
625
900
  "relationDates.status": 1,
626
901
  vendorId: 1
627
902
  });
628
- var RelationModel = import_mongoose6.default.models.Relation || import_mongoose6.default.model("Relation", RelationTypeSchema);
903
+ var RelationModel = import_mongoose10.default.models.Relation || import_mongoose10.default.model("Relation", RelationTypeSchema);
629
904
 
630
905
  // src/mongoose/global.ts
631
- var MongooseSchema7 = import_mongoose7.default.Schema;
906
+ var MongooseSchema7 = import_mongoose11.default.Schema;
632
907
  var OwnerTypeSchema = new MongooseSchema7(
633
908
  {
634
909
  email: { required: true, type: String },
635
910
  userId: {
636
911
  ref: "User",
637
912
  required: true,
638
- type: import_mongoose7.default.Schema.Types.ObjectId
913
+ type: import_mongoose11.default.Schema.Types.ObjectId
639
914
  }
640
915
  },
641
916
  { _id: false }
@@ -694,12 +969,12 @@ var userLicenseSchema = new MongooseSchema7(
694
969
  expiryDate: { required: true, type: Date },
695
970
  issuedDate: { required: true, type: Date },
696
971
  licenceType: {
697
- enum: Object.values(import_cluemart_shared7.EnumUserLicence),
972
+ enum: Object.values(import_cluemart_shared9.EnumUserLicence),
698
973
  required: true,
699
974
  type: String
700
975
  },
701
976
  prevLicenceType: {
702
- enum: Object.values(import_cluemart_shared7.EnumUserLicence),
977
+ enum: Object.values(import_cluemart_shared9.EnumUserLicence),
703
978
  required: false,
704
979
  type: String
705
980
  }
@@ -742,7 +1017,7 @@ var resourceRelationsSchema = new MongooseSchema7(
742
1017
  relationId: {
743
1018
  ref: "Relation",
744
1019
  required: false,
745
- type: import_mongoose7.default.Schema.Types.ObjectId
1020
+ type: import_mongoose11.default.Schema.Types.ObjectId
746
1021
  }
747
1022
  },
748
1023
  { _id: false }
@@ -750,7 +1025,7 @@ var resourceRelationsSchema = new MongooseSchema7(
750
1025
  var dateTimeSchema2 = new MongooseSchema7(
751
1026
  {
752
1027
  dateStatus: {
753
- enum: Object.values(import_cluemart_shared7.EnumEventDateStatus),
1028
+ enum: Object.values(import_cluemart_shared9.EnumEventDateStatus),
754
1029
  required: false,
755
1030
  type: String
756
1031
  },
@@ -793,11 +1068,11 @@ var relatedPostSchema = new MongooseSchema7(
793
1068
  postId: {
794
1069
  ref: "Post",
795
1070
  required: true,
796
- type: import_mongoose7.default.Schema.Types.ObjectId
1071
+ type: import_mongoose11.default.Schema.Types.ObjectId
797
1072
  },
798
1073
  postSlug: { required: true, type: String },
799
1074
  postType: {
800
- enum: Object.values(import_cluemart_shared7.EnumPostType),
1075
+ enum: Object.values(import_cluemart_shared9.EnumPostType),
801
1076
  required: true,
802
1077
  type: String
803
1078
  }
@@ -818,7 +1093,7 @@ var baseResourceFields = {
818
1093
  adIds: {
819
1094
  ref: "Ad",
820
1095
  required: false,
821
- type: [import_mongoose7.default.Schema.Types.ObjectId]
1096
+ type: [import_mongoose11.default.Schema.Types.ObjectId]
822
1097
  },
823
1098
  approvedAt: { default: null, required: false, type: Date },
824
1099
  contactDetails: { required: false, type: ContactDetailsSchema },
@@ -848,8 +1123,8 @@ var baseResourceFields = {
848
1123
  };
849
1124
 
850
1125
  // src/mongoose/GoogleImportedMarket.ts
851
- var import_cluemart_shared8 = require("@timardex/cluemart-shared");
852
- var import_mongoose8 = __toESM(require("mongoose"));
1126
+ var import_cluemart_shared10 = require("@timardex/cluemart-shared");
1127
+ var import_mongoose12 = __toESM(require("mongoose"));
853
1128
 
854
1129
  // src/mongoose/searchNamePlugin.ts
855
1130
  function deriveSearchName(name) {
@@ -895,15 +1170,15 @@ function syncSearchNameInUpdate(update) {
895
1170
  }
896
1171
  return null;
897
1172
  }
898
- function searchNamePlugin(schema20) {
899
- schema20.add({ searchName: { default: "", required: false, type: String } });
900
- schema20.index({ searchName: 1 });
901
- schema20.pre("save", function syncSearchNameOnSave(next) {
1173
+ function searchNamePlugin(schema24) {
1174
+ schema24.add({ searchName: { default: "", required: false, type: String } });
1175
+ schema24.index({ searchName: 1 });
1176
+ schema24.pre("save", function syncSearchNameOnSave(next) {
902
1177
  const doc = this;
903
1178
  doc.searchName = deriveSearchName(doc.name);
904
1179
  next();
905
1180
  });
906
- schema20.pre("insertMany", function syncSearchNameOnInsertMany(next, docs) {
1181
+ schema24.pre("insertMany", function syncSearchNameOnInsertMany(next, docs) {
907
1182
  const list = Array.isArray(docs) ? docs : [docs];
908
1183
  for (const doc of list) {
909
1184
  if (doc && typeof doc.name === "string") {
@@ -912,7 +1187,7 @@ function searchNamePlugin(schema20) {
912
1187
  }
913
1188
  next();
914
1189
  });
915
- schema20.pre("bulkWrite", function syncSearchNameOnBulkWrite(next, ops) {
1190
+ schema24.pre("bulkWrite", function syncSearchNameOnBulkWrite(next, ops) {
916
1191
  for (const op of ops) {
917
1192
  const doc = op.insertOne?.document ?? op.replaceOne?.replacement;
918
1193
  if (doc && typeof doc.name === "string") {
@@ -938,14 +1213,14 @@ function searchNamePlugin(schema20) {
938
1213
  }
939
1214
  next();
940
1215
  };
941
- schema20.pre(
1216
+ schema24.pre(
942
1217
  ["findOneAndUpdate", "updateOne", "updateMany"],
943
1218
  syncSearchNameOnUpdate
944
1219
  );
945
1220
  }
946
1221
 
947
1222
  // src/mongoose/GoogleImportedMarket.ts
948
- var MongooseSchema8 = import_mongoose8.default.Schema;
1223
+ var MongooseSchema8 = import_mongoose12.default.Schema;
949
1224
  var addressComponentSchema = new MongooseSchema8(
950
1225
  {
951
1226
  longName: { required: false, type: String },
@@ -954,7 +1229,7 @@ var addressComponentSchema = new MongooseSchema8(
954
1229
  },
955
1230
  { _id: false }
956
1231
  );
957
- var schema4 = new MongooseSchema8(
1232
+ var schema8 = new MongooseSchema8(
958
1233
  {
959
1234
  active: { default: false, required: true, type: Boolean },
960
1235
  address: { required: true, type: String },
@@ -966,7 +1241,7 @@ var schema4 = new MongooseSchema8(
966
1241
  claimedByUserId: {
967
1242
  ref: "User",
968
1243
  required: false,
969
- type: import_mongoose8.default.Schema.Types.ObjectId
1244
+ type: import_mongoose12.default.Schema.Types.ObjectId
970
1245
  },
971
1246
  cover: {
972
1247
  required: false,
@@ -978,10 +1253,10 @@ var schema4 = new MongooseSchema8(
978
1253
  eventId: {
979
1254
  ref: "Event",
980
1255
  required: false,
981
- type: import_mongoose8.default.Schema.Types.ObjectId
1256
+ type: import_mongoose12.default.Schema.Types.ObjectId
982
1257
  },
983
1258
  eventType: {
984
- enum: Object.values(import_cluemart_shared8.EnumEventType),
1259
+ enum: Object.values(import_cluemart_shared10.EnumEventType),
985
1260
  required: true,
986
1261
  type: String
987
1262
  },
@@ -1017,27 +1292,27 @@ var schema4 = new MongooseSchema8(
1017
1292
  },
1018
1293
  { timestamps: true }
1019
1294
  );
1020
- schema4.index({ "location.geo": "2dsphere" });
1021
- schema4.index({ name: 1 });
1022
- schema4.index({ region: 1 });
1023
- schema4.index({ deletedAt: 1 });
1024
- schema4.index({ "dateTime.dateStatus": 1 });
1025
- schema4.index({ slug: 1 });
1026
- schema4.index({ name: "text", description: "text" });
1027
- schema4.plugin(searchNamePlugin);
1028
- var GoogleImportedMarketModel = import_mongoose8.default.models.GoogleImportedMarket || import_mongoose8.default.model("GoogleImportedMarket", schema4);
1295
+ schema8.index({ "location.geo": "2dsphere" });
1296
+ schema8.index({ name: 1 });
1297
+ schema8.index({ region: 1 });
1298
+ schema8.index({ deletedAt: 1 });
1299
+ schema8.index({ "dateTime.dateStatus": 1 });
1300
+ schema8.index({ slug: 1 });
1301
+ schema8.index({ name: "text", description: "text" });
1302
+ schema8.plugin(searchNamePlugin);
1303
+ var GoogleImportedMarketModel = import_mongoose12.default.models.GoogleImportedMarket || import_mongoose12.default.model("GoogleImportedMarket", schema8);
1029
1304
 
1030
1305
  // src/mongoose/Notification.ts
1031
- var import_cluemart_shared9 = require("@timardex/cluemart-shared");
1032
- var import_mongoose9 = __toESM(require("mongoose"));
1033
- var MongooseSchema9 = import_mongoose9.default.Schema;
1034
- var schema5 = new MongooseSchema9(
1306
+ var import_cluemart_shared11 = require("@timardex/cluemart-shared");
1307
+ var import_mongoose13 = __toESM(require("mongoose"));
1308
+ var MongooseSchema9 = import_mongoose13.default.Schema;
1309
+ var schema9 = new MongooseSchema9(
1035
1310
  {
1036
1311
  data: {
1037
1312
  resourceId: { required: true, type: String },
1038
1313
  resourceName: { required: true, type: String },
1039
1314
  resourceType: {
1040
- enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1315
+ enum: Object.values(import_cluemart_shared11.EnumNotificationResourceType),
1041
1316
  required: true,
1042
1317
  type: String
1043
1318
  }
@@ -1046,28 +1321,28 @@ var schema5 = new MongooseSchema9(
1046
1321
  message: { required: true, type: String },
1047
1322
  title: { required: true, type: String },
1048
1323
  type: {
1049
- default: import_cluemart_shared9.EnumNotificationType.SYSTEM,
1050
- enum: Object.values(import_cluemart_shared9.EnumNotificationType),
1324
+ default: import_cluemart_shared11.EnumNotificationType.SYSTEM,
1325
+ enum: Object.values(import_cluemart_shared11.EnumNotificationType),
1051
1326
  required: true,
1052
1327
  type: String
1053
1328
  },
1054
1329
  userId: {
1055
1330
  ref: "User",
1056
1331
  required: true,
1057
- type: import_mongoose9.default.Schema.Types.ObjectId
1332
+ type: import_mongoose13.default.Schema.Types.ObjectId
1058
1333
  }
1059
1334
  },
1060
1335
  { timestamps: true }
1061
1336
  );
1062
- schema5.index({ isRead: 1, userId: 1 });
1063
- schema5.index({ createdAt: -1, userId: 1 });
1064
- var NotificationModel = import_mongoose9.default.models.Notification || import_mongoose9.default.model("Notification", schema5);
1337
+ schema9.index({ isRead: 1, userId: 1 });
1338
+ schema9.index({ createdAt: -1, userId: 1 });
1339
+ var NotificationModel = import_mongoose13.default.models.Notification || import_mongoose13.default.model("Notification", schema9);
1065
1340
 
1066
1341
  // src/mongoose/PushToken.ts
1067
1342
  var import_enums = require("@timardex/cluemart-shared/enums");
1068
- var import_mongoose10 = __toESM(require("mongoose"));
1069
- var MongooseSchema10 = import_mongoose10.default.Schema;
1070
- var schema6 = new MongooseSchema10(
1343
+ var import_mongoose14 = __toESM(require("mongoose"));
1344
+ var MongooseSchema10 = import_mongoose14.default.Schema;
1345
+ var schema10 = new MongooseSchema10(
1071
1346
  {
1072
1347
  platform: {
1073
1348
  enum: Object.values(import_enums.EnumOSPlatform),
@@ -1078,26 +1353,26 @@ var schema6 = new MongooseSchema10(
1078
1353
  userId: {
1079
1354
  ref: "User",
1080
1355
  required: true,
1081
- type: import_mongoose10.default.Schema.Types.ObjectId
1356
+ type: import_mongoose14.default.Schema.Types.ObjectId
1082
1357
  }
1083
1358
  },
1084
1359
  { timestamps: true }
1085
1360
  );
1086
- var PushTokenModel = import_mongoose10.default.models.PushToken || import_mongoose10.default.model("PushToken", schema6);
1361
+ var PushTokenModel = import_mongoose14.default.models.PushToken || import_mongoose14.default.model("PushToken", schema10);
1087
1362
 
1088
1363
  // src/mongoose/ResourceActivity.ts
1089
- var import_cluemart_shared10 = require("@timardex/cluemart-shared");
1090
- var import_mongoose11 = __toESM(require("mongoose"));
1091
- var MongooseSchema11 = import_mongoose11.default.Schema;
1364
+ var import_cluemart_shared12 = require("@timardex/cluemart-shared");
1365
+ var import_mongoose15 = __toESM(require("mongoose"));
1366
+ var MongooseSchema11 = import_mongoose15.default.Schema;
1092
1367
  var ActivitySchema = new MongooseSchema11(
1093
1368
  {
1094
1369
  activityType: {
1095
- enum: Object.values(import_cluemart_shared10.EnumActivity),
1370
+ enum: Object.values(import_cluemart_shared12.EnumActivity),
1096
1371
  required: true,
1097
1372
  type: String
1098
1373
  },
1099
1374
  dateStatus: {
1100
- enum: Object.values(import_cluemart_shared10.EnumEventDateStatus),
1375
+ enum: Object.values(import_cluemart_shared12.EnumEventDateStatus),
1101
1376
  required: false,
1102
1377
  type: String
1103
1378
  },
@@ -1109,7 +1384,7 @@ var ActivitySchema = new MongooseSchema11(
1109
1384
  startTime: { required: false, type: String },
1110
1385
  timestamp: { default: Date.now, type: Date },
1111
1386
  userAgent: {
1112
- enum: Object.values(import_cluemart_shared10.EnumOSPlatform),
1387
+ enum: Object.values(import_cluemart_shared12.EnumOSPlatform),
1113
1388
  required: true,
1114
1389
  type: String
1115
1390
  },
@@ -1117,33 +1392,33 @@ var ActivitySchema = new MongooseSchema11(
1117
1392
  },
1118
1393
  { _id: false }
1119
1394
  );
1120
- var schema7 = new MongooseSchema11(
1395
+ var schema11 = new MongooseSchema11(
1121
1396
  {
1122
1397
  activity: { default: [], type: [ActivitySchema] },
1123
1398
  resourceId: { required: true, type: String },
1124
1399
  resourceType: {
1125
- enum: Object.values(import_cluemart_shared10.EnumResourceType),
1400
+ enum: Object.values(import_cluemart_shared12.EnumResourceType),
1126
1401
  required: true,
1127
1402
  type: String
1128
1403
  }
1129
1404
  },
1130
1405
  { timestamps: true }
1131
1406
  );
1132
- schema7.index({ resourceId: 1, resourceType: 1 }, { unique: true });
1133
- schema7.index({ "views.location": "2dsphere" });
1134
- var ResourceActivityModel = import_mongoose11.default.models.ResourceActivity || import_mongoose11.default.model("ResourceActivity", schema7);
1407
+ schema11.index({ resourceId: 1, resourceType: 1 }, { unique: true });
1408
+ schema11.index({ "views.location": "2dsphere" });
1409
+ var ResourceActivityModel = import_mongoose15.default.models.ResourceActivity || import_mongoose15.default.model("ResourceActivity", schema11);
1135
1410
 
1136
1411
  // src/mongoose/User.ts
1137
- var import_cluemart_shared11 = require("@timardex/cluemart-shared");
1138
- var import_mongoose12 = __toESM(require("mongoose"));
1139
- var MongooseSchema12 = import_mongoose12.default.Schema;
1412
+ var import_cluemart_shared13 = require("@timardex/cluemart-shared");
1413
+ var import_mongoose16 = __toESM(require("mongoose"));
1414
+ var MongooseSchema12 = import_mongoose16.default.Schema;
1140
1415
  var userActivityEventSchema = new MongooseSchema12(
1141
1416
  {
1142
1417
  dateTime: dateTimeSchema2,
1143
1418
  resourceId: {
1144
1419
  ref: "Event",
1145
1420
  required: false,
1146
- type: import_mongoose12.default.Schema.Types.ObjectId
1421
+ type: import_mongoose16.default.Schema.Types.ObjectId
1147
1422
  }
1148
1423
  },
1149
1424
  { _id: false }
@@ -1153,17 +1428,17 @@ var userActivityFavouritesSchema = new MongooseSchema12(
1153
1428
  events: {
1154
1429
  ref: "Event",
1155
1430
  required: false,
1156
- type: [import_mongoose12.default.Schema.Types.ObjectId]
1431
+ type: [import_mongoose16.default.Schema.Types.ObjectId]
1157
1432
  },
1158
1433
  partners: {
1159
1434
  ref: "Partner",
1160
1435
  required: false,
1161
- type: [import_mongoose12.default.Schema.Types.ObjectId]
1436
+ type: [import_mongoose16.default.Schema.Types.ObjectId]
1162
1437
  },
1163
1438
  vendors: {
1164
1439
  ref: "Vendor",
1165
1440
  required: false,
1166
- type: [import_mongoose12.default.Schema.Types.ObjectId]
1441
+ type: [import_mongoose16.default.Schema.Types.ObjectId]
1167
1442
  }
1168
1443
  },
1169
1444
  { _id: false }
@@ -1171,7 +1446,7 @@ var userActivityFavouritesSchema = new MongooseSchema12(
1171
1446
  var stripeSchema = new MongooseSchema12(
1172
1447
  {
1173
1448
  billingPeriod: {
1174
- enum: Object.values(import_cluemart_shared11.EnumBillingPeriod),
1449
+ enum: Object.values(import_cluemart_shared13.EnumBillingPeriod),
1175
1450
  required: false,
1176
1451
  type: String
1177
1452
  },
@@ -1180,7 +1455,7 @@ var stripeSchema = new MongooseSchema12(
1180
1455
  type: Boolean
1181
1456
  },
1182
1457
  currentPlan: {
1183
- enum: Object.values(import_cluemart_shared11.EnumUserLicence),
1458
+ enum: Object.values(import_cluemart_shared13.EnumUserLicence),
1184
1459
  required: false,
1185
1460
  type: String
1186
1461
  },
@@ -1192,8 +1467,20 @@ var stripeSchema = new MongooseSchema12(
1192
1467
  required: false,
1193
1468
  type: Date
1194
1469
  },
1470
+ paymentFailedAt: {
1471
+ required: false,
1472
+ type: Date
1473
+ },
1474
+ paymentGracePeriodEndsAt: {
1475
+ required: false,
1476
+ type: Date
1477
+ },
1478
+ paymentGraceSubscriptionId: {
1479
+ required: false,
1480
+ type: String
1481
+ },
1195
1482
  pendingBillingPeriod: {
1196
- enum: Object.values(import_cluemart_shared11.EnumBillingPeriod),
1483
+ enum: Object.values(import_cluemart_shared13.EnumBillingPeriod),
1197
1484
  required: false,
1198
1485
  type: String
1199
1486
  },
@@ -1202,7 +1489,7 @@ var stripeSchema = new MongooseSchema12(
1202
1489
  type: Date
1203
1490
  },
1204
1491
  pendingPlan: {
1205
- enum: Object.values(import_cluemart_shared11.EnumUserLicence),
1492
+ enum: Object.values(import_cluemart_shared13.EnumUserLicence),
1206
1493
  required: false,
1207
1494
  type: String
1208
1495
  },
@@ -1219,7 +1506,7 @@ var stripeSchema = new MongooseSchema12(
1219
1506
  type: Date
1220
1507
  },
1221
1508
  status: {
1222
- enum: Object.values(import_cluemart_shared11.EnumSubscriptionStatus),
1509
+ enum: Object.values(import_cluemart_shared13.EnumSubscriptionStatus),
1223
1510
  required: false,
1224
1511
  type: String
1225
1512
  },
@@ -1241,7 +1528,7 @@ var stripeSchema = new MongooseSchema12(
1241
1528
  var redeemedRewardSchema = new MongooseSchema12(
1242
1529
  {
1243
1530
  name: {
1244
- enum: Object.values(import_cluemart_shared11.EnumReward),
1531
+ enum: Object.values(import_cluemart_shared13.EnumReward),
1245
1532
  required: true,
1246
1533
  type: String
1247
1534
  },
@@ -1250,13 +1537,13 @@ var redeemedRewardSchema = new MongooseSchema12(
1250
1537
  },
1251
1538
  { _id: false }
1252
1539
  );
1253
- var schema8 = new MongooseSchema12(
1540
+ var schema12 = new MongooseSchema12(
1254
1541
  {
1255
1542
  active: { default: false, required: true, type: Boolean },
1256
1543
  affiliate: {
1257
1544
  ref: "Affiliate",
1258
1545
  required: false,
1259
- type: import_mongoose12.default.Schema.Types.ObjectId
1546
+ type: import_mongoose16.default.Schema.Types.ObjectId
1260
1547
  },
1261
1548
  avatar: {
1262
1549
  required: false,
@@ -1265,28 +1552,28 @@ var schema8 = new MongooseSchema12(
1265
1552
  coupon: {
1266
1553
  ref: "Coupon",
1267
1554
  required: false,
1268
- type: import_mongoose12.default.Schema.Types.ObjectId
1555
+ type: import_mongoose16.default.Schema.Types.ObjectId
1269
1556
  },
1270
1557
  deletedAt: { default: null, required: false, type: Date },
1271
1558
  email: { required: true, type: String },
1272
1559
  emailSentFor: {
1273
- enum: Object.values(import_cluemart_shared11.EnumNotificationResourceType),
1560
+ enum: Object.values(import_cluemart_shared13.EnumNotificationResourceType),
1274
1561
  required: false,
1275
1562
  type: [String]
1276
1563
  },
1277
1564
  events: {
1278
1565
  ref: "Event",
1279
1566
  required: false,
1280
- type: [import_mongoose12.default.Schema.Types.ObjectId]
1567
+ type: [import_mongoose16.default.Schema.Types.ObjectId]
1281
1568
  },
1282
1569
  firstName: { required: true, type: String },
1283
1570
  game: {
1284
1571
  ref: "Game",
1285
1572
  required: false,
1286
- type: import_mongoose12.default.Schema.Types.ObjectId
1573
+ type: import_mongoose16.default.Schema.Types.ObjectId
1287
1574
  },
1288
1575
  interests: {
1289
- enum: Object.values(import_cluemart_shared11.EnumResourceType),
1576
+ enum: Object.values(import_cluemart_shared13.EnumResourceType),
1290
1577
  required: false,
1291
1578
  type: [String]
1292
1579
  },
@@ -1305,11 +1592,11 @@ var schema8 = new MongooseSchema12(
1305
1592
  partner: {
1306
1593
  ref: "Partner",
1307
1594
  required: false,
1308
- type: import_mongoose12.default.Schema.Types.ObjectId
1595
+ type: import_mongoose16.default.Schema.Types.ObjectId
1309
1596
  },
1310
1597
  password: { required: true, type: String },
1311
1598
  platform: {
1312
- enum: Object.values(import_cluemart_shared11.EnumOSPlatform),
1599
+ enum: Object.values(import_cluemart_shared13.EnumOSPlatform),
1313
1600
  required: false,
1314
1601
  type: String
1315
1602
  },
@@ -1330,15 +1617,15 @@ var schema8 = new MongooseSchema12(
1330
1617
  type: String
1331
1618
  },
1332
1619
  roles: {
1333
- default: [import_cluemart_shared11.EnumUserRole.CUSTOMER],
1334
- enum: Object.values(import_cluemart_shared11.EnumUserRole),
1620
+ default: [import_cluemart_shared13.EnumUserRole.CUSTOMER],
1621
+ enum: Object.values(import_cluemart_shared13.EnumUserRole),
1335
1622
  required: true,
1336
1623
  type: [String]
1337
1624
  },
1338
1625
  school: {
1339
1626
  ref: "School",
1340
1627
  required: false,
1341
- type: import_mongoose12.default.Schema.Types.ObjectId
1628
+ type: import_mongoose16.default.Schema.Types.ObjectId
1342
1629
  },
1343
1630
  stripe: {
1344
1631
  required: false,
@@ -1363,20 +1650,20 @@ var schema8 = new MongooseSchema12(
1363
1650
  vendor: {
1364
1651
  ref: "Vendor",
1365
1652
  required: false,
1366
- type: import_mongoose12.default.Schema.Types.ObjectId
1653
+ type: import_mongoose16.default.Schema.Types.ObjectId
1367
1654
  }
1368
1655
  },
1369
1656
  { strict: false, timestamps: true }
1370
1657
  );
1371
- schema8.index({ "licences.expiryDate": 1 });
1372
- schema8.index({ "licences.licenceType": 1 });
1373
- schema8.index({ promoCodes: 1, active: 1, deletedAt: 1 });
1374
- var UserModel = import_mongoose12.default.models.User || import_mongoose12.default.model("User", schema8);
1658
+ schema12.index({ "licences.expiryDate": 1 });
1659
+ schema12.index({ "licences.licenceType": 1 });
1660
+ schema12.index({ promoCodes: 1, active: 1, deletedAt: 1 });
1661
+ var UserModel = import_mongoose16.default.models.User || import_mongoose16.default.model("User", schema12);
1375
1662
 
1376
1663
  // src/mongoose/VerificationToken.ts
1377
- var import_mongoose13 = __toESM(require("mongoose"));
1378
- var MongooseSchema13 = import_mongoose13.default.Schema;
1379
- var schema9 = new MongooseSchema13(
1664
+ var import_mongoose17 = __toESM(require("mongoose"));
1665
+ var MongooseSchema13 = import_mongoose17.default.Schema;
1666
+ var schema13 = new MongooseSchema13(
1380
1667
  {
1381
1668
  createdAt: {
1382
1669
  default: Date.now,
@@ -1391,12 +1678,12 @@ var schema9 = new MongooseSchema13(
1391
1678
  },
1392
1679
  { timestamps: true }
1393
1680
  );
1394
- var VerificationTokenModel = import_mongoose13.default.models.VerificationToken || import_mongoose13.default.model("VerificationToken", schema9);
1681
+ var VerificationTokenModel = import_mongoose17.default.models.VerificationToken || import_mongoose17.default.model("VerificationToken", schema13);
1395
1682
 
1396
1683
  // src/mongoose/vendor/Vendor.ts
1397
- var import_cluemart_shared12 = require("@timardex/cluemart-shared");
1398
- var import_mongoose14 = __toESM(require("mongoose"));
1399
- var MongooseSchema14 = import_mongoose14.default.Schema;
1684
+ var import_cluemart_shared14 = require("@timardex/cluemart-shared");
1685
+ var import_mongoose18 = __toESM(require("mongoose"));
1686
+ var MongooseSchema14 = import_mongoose18.default.Schema;
1400
1687
  var vendorProductTypeSchema = new MongooseSchema14(
1401
1688
  {
1402
1689
  description: { required: false, type: String },
@@ -1419,7 +1706,7 @@ var calendarSchema = new MongooseSchema14(
1419
1706
  {
1420
1707
  dateTime: {
1421
1708
  dateStatus: {
1422
- enum: Object.values(import_cluemart_shared12.EnumEventDateStatus),
1709
+ enum: Object.values(import_cluemart_shared14.EnumEventDateStatus),
1423
1710
  required: false,
1424
1711
  type: String
1425
1712
  },
@@ -1459,7 +1746,7 @@ var downgradeSnapshotSchema = new MongooseSchema14(
1459
1746
  },
1460
1747
  { _id: false }
1461
1748
  );
1462
- var schema10 = new MongooseSchema14(
1749
+ var schema14 = new MongooseSchema14(
1463
1750
  {
1464
1751
  ...baseResourceFields,
1465
1752
  // Importing base resource fields from global.ts
@@ -1483,39 +1770,39 @@ var schema10 = new MongooseSchema14(
1483
1770
  unregisteredVendorId: {
1484
1771
  ref: "UnregisteredVendor",
1485
1772
  required: false,
1486
- type: import_mongoose14.default.Schema.Types.ObjectId
1773
+ type: import_mongoose18.default.Schema.Types.ObjectId
1487
1774
  },
1488
1775
  vendorInfoId: {
1489
1776
  ref: "VendorInfo",
1490
1777
  required: false,
1491
- type: import_mongoose14.default.Schema.Types.ObjectId
1778
+ type: import_mongoose18.default.Schema.Types.ObjectId
1492
1779
  },
1493
1780
  vendorType: {
1494
- enum: Object.values(import_cluemart_shared12.EnumVendorType),
1781
+ enum: Object.values(import_cluemart_shared14.EnumVendorType),
1495
1782
  required: true,
1496
1783
  type: String
1497
1784
  }
1498
1785
  },
1499
1786
  { timestamps: true }
1500
1787
  );
1501
- schema10.index({ name: 1 });
1502
- schema10.index({ description: 1 });
1503
- schema10.index({ region: 1 });
1504
- schema10.index({ "categories.name": 1 });
1505
- schema10.index({ slug: 1 });
1506
- schema10.index({
1788
+ schema14.index({ name: 1 });
1789
+ schema14.index({ description: 1 });
1790
+ schema14.index({ region: 1 });
1791
+ schema14.index({ "categories.name": 1 });
1792
+ schema14.index({ slug: 1 });
1793
+ schema14.index({
1507
1794
  categoriesNames: "text",
1508
1795
  description: "text",
1509
1796
  name: "text"
1510
1797
  });
1511
- schema10.index({ deletedAt: 1, "owner.userId": 1 });
1512
- schema10.plugin(searchNamePlugin);
1513
- var VendorModel = import_mongoose14.default.models.Vendor || import_mongoose14.default.model("Vendor", schema10);
1798
+ schema14.index({ deletedAt: 1, "owner.userId": 1 });
1799
+ schema14.plugin(searchNamePlugin);
1800
+ var VendorModel = import_mongoose18.default.models.Vendor || import_mongoose18.default.model("Vendor", schema14);
1514
1801
 
1515
1802
  // src/mongoose/vendor/VendorInfo.ts
1516
- var import_cluemart_shared13 = require("@timardex/cluemart-shared");
1517
- var import_mongoose15 = __toESM(require("mongoose"));
1518
- var MongooseSchema15 = import_mongoose15.default.Schema;
1803
+ var import_cluemart_shared15 = require("@timardex/cluemart-shared");
1804
+ var import_mongoose19 = __toESM(require("mongoose"));
1805
+ var MongooseSchema15 = import_mongoose19.default.Schema;
1519
1806
  var AttributesSchema = new MongooseSchema15(
1520
1807
  {
1521
1808
  details: { required: false, type: String },
@@ -1523,7 +1810,7 @@ var AttributesSchema = new MongooseSchema15(
1523
1810
  },
1524
1811
  { _id: false }
1525
1812
  );
1526
- var schema11 = new MongooseSchema15(
1813
+ var schema15 = new MongooseSchema15(
1527
1814
  {
1528
1815
  active: { default: true, type: Boolean },
1529
1816
  compliance: {
@@ -1533,7 +1820,7 @@ var schema11 = new MongooseSchema15(
1533
1820
  documents: [ResourceImageTypeSchema],
1534
1821
  product: {
1535
1822
  foodFlavors: {
1536
- enum: Object.values(import_cluemart_shared13.EnumFoodFlavor),
1823
+ enum: Object.values(import_cluemart_shared15.EnumFoodFlavor),
1537
1824
  required: true,
1538
1825
  type: [String]
1539
1826
  },
@@ -1558,29 +1845,29 @@ var schema11 = new MongooseSchema15(
1558
1845
  vendorId: {
1559
1846
  ref: "Vendor",
1560
1847
  required: true,
1561
- type: import_mongoose15.default.Schema.Types.ObjectId
1848
+ type: import_mongoose19.default.Schema.Types.ObjectId
1562
1849
  }
1563
1850
  },
1564
1851
  { timestamps: true }
1565
1852
  );
1566
- schema11.index({ vendorId: 1 });
1567
- var VendorInfoModel = import_mongoose15.default.models.VendorInfo || import_mongoose15.default.model("VendorInfo", schema11);
1853
+ schema15.index({ vendorId: 1 });
1854
+ var VendorInfoModel = import_mongoose19.default.models.VendorInfo || import_mongoose19.default.model("VendorInfo", schema15);
1568
1855
 
1569
1856
  // src/mongoose/vendor/UnregisteredVendor.ts
1570
- var import_mongoose16 = __toESM(require("mongoose"));
1571
- var MongooseSchema16 = import_mongoose16.default.Schema;
1857
+ var import_mongoose20 = __toESM(require("mongoose"));
1858
+ var MongooseSchema16 = import_mongoose20.default.Schema;
1572
1859
  var invitationSchema = new MongooseSchema16(
1573
1860
  {
1574
1861
  dateTime: { required: true, type: [dateTimeSchema2] },
1575
1862
  inviterId: {
1576
1863
  ref: "Event",
1577
1864
  required: true,
1578
- type: import_mongoose16.default.Schema.Types.ObjectId
1865
+ type: import_mongoose20.default.Schema.Types.ObjectId
1579
1866
  }
1580
1867
  },
1581
1868
  { _id: false }
1582
1869
  );
1583
- var schema12 = new MongooseSchema16(
1870
+ var schema16 = new MongooseSchema16(
1584
1871
  {
1585
1872
  active: { default: true, required: true, type: Boolean },
1586
1873
  categoryIds: { required: true, type: [String] },
@@ -1589,7 +1876,7 @@ var schema12 = new MongooseSchema16(
1589
1876
  claimedByUserId: {
1590
1877
  ref: "User",
1591
1878
  required: false,
1592
- type: import_mongoose16.default.Schema.Types.ObjectId
1879
+ type: import_mongoose20.default.Schema.Types.ObjectId
1593
1880
  },
1594
1881
  claimInitiatedAt: { default: null, required: false, type: Date },
1595
1882
  claimToken: { default: null, required: false, type: String },
@@ -1602,15 +1889,15 @@ var schema12 = new MongooseSchema16(
1602
1889
  },
1603
1890
  { timestamps: true }
1604
1891
  );
1605
- schema12.index({ name: 1 });
1606
- schema12.index({ email: 1 });
1607
- var UnregisteredVendorModel = import_mongoose16.default.models.UnregisteredVendor || import_mongoose16.default.model("UnregisteredVendor", schema12);
1892
+ schema16.index({ name: 1 });
1893
+ schema16.index({ email: 1 });
1894
+ var UnregisteredVendorModel = import_mongoose20.default.models.UnregisteredVendor || import_mongoose20.default.model("UnregisteredVendor", schema16);
1608
1895
 
1609
1896
  // src/mongoose/event/Event.ts
1610
- var import_cluemart_shared14 = require("@timardex/cluemart-shared");
1611
- var import_mongoose17 = __toESM(require("mongoose"));
1612
- var MongooseSchema17 = import_mongoose17.default.Schema;
1613
- var schema13 = new MongooseSchema17(
1897
+ var import_cluemart_shared16 = require("@timardex/cluemart-shared");
1898
+ var import_mongoose21 = __toESM(require("mongoose"));
1899
+ var MongooseSchema17 = import_mongoose21.default.Schema;
1900
+ var schema17 = new MongooseSchema17(
1614
1901
  {
1615
1902
  ...baseResourceFields,
1616
1903
  // Importing base resource fields from global.ts
@@ -1619,10 +1906,10 @@ var schema13 = new MongooseSchema17(
1619
1906
  eventInfoId: {
1620
1907
  ref: "EventInfo",
1621
1908
  required: false,
1622
- type: import_mongoose17.default.Schema.Types.ObjectId
1909
+ type: import_mongoose21.default.Schema.Types.ObjectId
1623
1910
  },
1624
1911
  eventType: {
1625
- enum: Object.values(import_cluemart_shared14.EnumEventType),
1912
+ enum: Object.values(import_cluemart_shared16.EnumEventType),
1626
1913
  required: true,
1627
1914
  type: String
1628
1915
  },
@@ -1648,24 +1935,24 @@ var schema13 = new MongooseSchema17(
1648
1935
  },
1649
1936
  { timestamps: true }
1650
1937
  );
1651
- schema13.index({ name: 1 });
1652
- schema13.index({ description: 1 });
1653
- schema13.index({ region: 1 });
1654
- schema13.index({ "location.geo": "2dsphere" });
1655
- schema13.index({ tags: 1 });
1656
- schema13.index({ deletedAt: 1 });
1657
- schema13.index({ "dateTime.dateStatus": 1 });
1658
- schema13.index({ slug: 1 });
1659
- schema13.index({ name: "text", description: "text", tags: "text" });
1660
- schema13.index({ "owner.userId": 1, deletedAt: 1 });
1661
- schema13.plugin(searchNamePlugin);
1662
- var EventModel = import_mongoose17.default.models.Event || import_mongoose17.default.model("Event", schema13);
1938
+ schema17.index({ name: 1 });
1939
+ schema17.index({ description: 1 });
1940
+ schema17.index({ region: 1 });
1941
+ schema17.index({ "location.geo": "2dsphere" });
1942
+ schema17.index({ tags: 1 });
1943
+ schema17.index({ deletedAt: 1 });
1944
+ schema17.index({ "dateTime.dateStatus": 1 });
1945
+ schema17.index({ slug: 1 });
1946
+ schema17.index({ name: "text", description: "text", tags: "text" });
1947
+ schema17.index({ "owner.userId": 1, deletedAt: 1 });
1948
+ schema17.plugin(searchNamePlugin);
1949
+ var EventModel = import_mongoose21.default.models.Event || import_mongoose21.default.model("Event", schema17);
1663
1950
 
1664
1951
  // src/mongoose/Partner.ts
1665
- var import_cluemart_shared15 = require("@timardex/cluemart-shared");
1666
- var import_mongoose18 = __toESM(require("mongoose"));
1667
- var MongooseSchema18 = import_mongoose18.default.Schema;
1668
- var schema14 = new MongooseSchema18(
1952
+ var import_cluemart_shared17 = require("@timardex/cluemart-shared");
1953
+ var import_mongoose22 = __toESM(require("mongoose"));
1954
+ var MongooseSchema18 = import_mongoose22.default.Schema;
1955
+ var schema18 = new MongooseSchema18(
1669
1956
  {
1670
1957
  ...baseResourceFields,
1671
1958
  location: {
@@ -1674,33 +1961,33 @@ var schema14 = new MongooseSchema18(
1674
1961
  },
1675
1962
  nzbn: { required: true, type: String },
1676
1963
  partnerType: {
1677
- enum: Object.values(import_cluemart_shared15.EnumPartnerType),
1964
+ enum: Object.values(import_cluemart_shared17.EnumPartnerType),
1678
1965
  required: true,
1679
1966
  type: String
1680
1967
  }
1681
1968
  },
1682
1969
  { timestamps: true }
1683
1970
  );
1684
- schema14.index({ name: 1 });
1685
- schema14.index({ description: 1 });
1686
- schema14.index({ region: 1 });
1687
- schema14.index({ "location.geo": "2dsphere" });
1688
- schema14.index({ slug: 1 });
1689
- schema14.index({ name: "text", description: "text" });
1690
- schema14.index({ "owner.userId": 1, deletedAt: 1 });
1691
- schema14.plugin(searchNamePlugin);
1692
- var PartnerModel = import_mongoose18.default.models.Partner || import_mongoose18.default.model("Partner", schema14);
1971
+ schema18.index({ name: 1 });
1972
+ schema18.index({ description: 1 });
1973
+ schema18.index({ region: 1 });
1974
+ schema18.index({ "location.geo": "2dsphere" });
1975
+ schema18.index({ slug: 1 });
1976
+ schema18.index({ name: "text", description: "text" });
1977
+ schema18.index({ "owner.userId": 1, deletedAt: 1 });
1978
+ schema18.plugin(searchNamePlugin);
1979
+ var PartnerModel = import_mongoose22.default.models.Partner || import_mongoose22.default.model("Partner", schema18);
1693
1980
 
1694
1981
  // src/mongoose/Post.ts
1695
- var import_cluemart_shared16 = require("@timardex/cluemart-shared");
1696
- var import_mongoose19 = __toESM(require("mongoose"));
1697
- var MongooseSchema19 = import_mongoose19.default.Schema;
1982
+ var import_cluemart_shared18 = require("@timardex/cluemart-shared");
1983
+ var import_mongoose23 = __toESM(require("mongoose"));
1984
+ var MongooseSchema19 = import_mongoose23.default.Schema;
1698
1985
  var contentSchema = new MongooseSchema19(
1699
1986
  {
1700
- contentData: import_mongoose19.Schema.Types.Mixed,
1987
+ contentData: import_mongoose23.Schema.Types.Mixed,
1701
1988
  contentOrder: { required: true, type: Number },
1702
1989
  contentType: {
1703
- enum: Object.values(import_cluemart_shared16.EnumPostContentType),
1990
+ enum: Object.values(import_cluemart_shared18.EnumPostContentType),
1704
1991
  required: true,
1705
1992
  type: String
1706
1993
  }
@@ -1713,14 +2000,14 @@ var resourceSchema = new MongooseSchema19(
1713
2000
  resourceRegion: { required: true, type: String },
1714
2001
  resourceSlug: { required: true, type: String },
1715
2002
  resourceType: {
1716
- enum: Object.values(import_cluemart_shared16.EnumResourceType),
2003
+ enum: Object.values(import_cluemart_shared18.EnumResourceType),
1717
2004
  required: true,
1718
2005
  type: String
1719
2006
  }
1720
2007
  },
1721
2008
  { _id: false }
1722
2009
  );
1723
- var schema15 = new MongooseSchema19(
2010
+ var schema19 = new MongooseSchema19(
1724
2011
  {
1725
2012
  active: { default: false, required: true, type: Boolean },
1726
2013
  approvedAt: { default: null, required: false, type: Date },
@@ -1736,7 +2023,7 @@ var schema15 = new MongooseSchema19(
1736
2023
  },
1737
2024
  deletedAt: { default: null, required: false, type: Date },
1738
2025
  postType: {
1739
- enum: Object.values(import_cluemart_shared16.EnumPostType),
2026
+ enum: Object.values(import_cluemart_shared18.EnumPostType),
1740
2027
  required: true,
1741
2028
  type: String
1742
2029
  },
@@ -1751,14 +2038,14 @@ var schema15 = new MongooseSchema19(
1751
2038
  },
1752
2039
  { timestamps: true }
1753
2040
  );
1754
- schema15.index({ title: 1 });
1755
- schema15.index({ tags: 1 });
1756
- schema15.index({ postType: 1, slug: 1 }, { unique: true });
1757
- var PostModel = import_mongoose19.default.models.Post || import_mongoose19.default.model("Post", schema15);
2041
+ schema19.index({ title: 1 });
2042
+ schema19.index({ tags: 1 });
2043
+ schema19.index({ postType: 1, slug: 1 }, { unique: true });
2044
+ var PostModel = import_mongoose23.default.models.Post || import_mongoose23.default.model("Post", schema19);
1758
2045
 
1759
2046
  // src/mongoose/AppSetting.ts
1760
- var import_mongoose20 = __toESM(require("mongoose"));
1761
- var MongooseSchema20 = import_mongoose20.default.Schema;
2047
+ var import_mongoose24 = __toESM(require("mongoose"));
2048
+ var MongooseSchema20 = import_mongoose24.default.Schema;
1762
2049
  var APP_SETTINGS_ID = "APP_SETTINGS_DOCUMENT_ID";
1763
2050
  var AppSettingSchema = new MongooseSchema20(
1764
2051
  {
@@ -1791,18 +2078,18 @@ var AppSettingSchema = new MongooseSchema20(
1791
2078
  },
1792
2079
  { timestamps: true }
1793
2080
  );
1794
- var AppSettingModel = import_mongoose20.default.models.AppSetting || import_mongoose20.default.model("AppSetting", AppSettingSchema);
2081
+ var AppSettingModel = import_mongoose24.default.models.AppSetting || import_mongoose24.default.model("AppSetting", AppSettingSchema);
1795
2082
 
1796
2083
  // src/mongoose/game/Game.ts
1797
- var import_cluemart_shared17 = require("@timardex/cluemart-shared");
1798
- var import_mongoose24 = __toESM(require("mongoose"));
2084
+ var import_cluemart_shared19 = require("@timardex/cluemart-shared");
2085
+ var import_mongoose28 = __toESM(require("mongoose"));
1799
2086
 
1800
2087
  // src/mongoose/game/DailyClue.ts
1801
- var import_mongoose22 = __toESM(require("mongoose"));
2088
+ var import_mongoose26 = __toESM(require("mongoose"));
1802
2089
 
1803
2090
  // src/mongoose/game/utils.ts
1804
- var import_mongoose21 = __toESM(require("mongoose"));
1805
- var MongooseSchema21 = import_mongoose21.default.Schema;
2091
+ var import_mongoose25 = __toESM(require("mongoose"));
2092
+ var MongooseSchema21 = import_mongoose25.default.Schema;
1806
2093
  var schemaGameDate = new MongooseSchema21(
1807
2094
  {
1808
2095
  endDate: { required: true, type: Date },
@@ -1812,7 +2099,7 @@ var schemaGameDate = new MongooseSchema21(
1812
2099
  );
1813
2100
 
1814
2101
  // src/mongoose/game/DailyClue.ts
1815
- var MongooseSchema22 = import_mongoose22.default.Schema;
2102
+ var MongooseSchema22 = import_mongoose26.default.Schema;
1816
2103
  var schemaLetters = new MongooseSchema22(
1817
2104
  {
1818
2105
  collected: { required: false, type: [String] },
@@ -1843,8 +2130,8 @@ var schemaDailyClueGameData = new MongooseSchema22(
1843
2130
  );
1844
2131
 
1845
2132
  // src/mongoose/game/PuzzleGame.ts
1846
- var import_mongoose23 = __toESM(require("mongoose"));
1847
- var MongooseSchema23 = import_mongoose23.default.Schema;
2133
+ var import_mongoose27 = __toESM(require("mongoose"));
2134
+ var MongooseSchema23 = import_mongoose27.default.Schema;
1848
2135
  var schemaPuzzleAnswer = new MongooseSchema23(
1849
2136
  {
1850
2137
  answer: { required: true, type: String },
@@ -1889,16 +2176,16 @@ var schemaPuzzleGameData = new MongooseSchema23(
1889
2176
  );
1890
2177
 
1891
2178
  // src/mongoose/game/Game.ts
1892
- var MongooseSchema24 = import_mongoose24.default.Schema;
2179
+ var MongooseSchema24 = import_mongoose28.default.Schema;
1893
2180
  var gameDataSchemas = {
1894
- [import_cluemart_shared17.EnumGameType.DAILY_CLUE]: schemaDailyClueGameData,
1895
- [import_cluemart_shared17.EnumGameType.MINI_QUIZ]: schemaPuzzleGameData,
1896
- [import_cluemart_shared17.EnumGameType.ODD_ONE_OUT]: schemaPuzzleGameData
2181
+ [import_cluemart_shared19.EnumGameType.DAILY_CLUE]: schemaDailyClueGameData,
2182
+ [import_cluemart_shared19.EnumGameType.MINI_QUIZ]: schemaPuzzleGameData,
2183
+ [import_cluemart_shared19.EnumGameType.ODD_ONE_OUT]: schemaPuzzleGameData
1897
2184
  };
1898
2185
  var gameDataDefinition = Object.fromEntries(
1899
- Object.entries(gameDataSchemas).map(([key, schema20]) => [
2186
+ Object.entries(gameDataSchemas).map(([key, schema24]) => [
1900
2187
  key,
1901
- { default: null, required: false, type: schema20 }
2188
+ { default: null, required: false, type: schema24 }
1902
2189
  ])
1903
2190
  );
1904
2191
  var gameHistorySchema = new MongooseSchema24(
@@ -1906,13 +2193,13 @@ var gameHistorySchema = new MongooseSchema24(
1906
2193
  createdAt: { required: true, type: Date },
1907
2194
  gameDate: { required: true, type: schemaGameDate },
1908
2195
  gameStatus: {
1909
- enum: Object.values(import_cluemart_shared17.EnumGameStatus),
2196
+ enum: Object.values(import_cluemart_shared19.EnumGameStatus),
1910
2197
  required: true,
1911
2198
  type: String
1912
2199
  },
1913
2200
  gameTitle: { required: true, type: String },
1914
2201
  gameType: {
1915
- enum: Object.values(import_cluemart_shared17.EnumGameType),
2202
+ enum: Object.values(import_cluemart_shared19.EnumGameType),
1916
2203
  required: true,
1917
2204
  type: String
1918
2205
  },
@@ -1928,7 +2215,7 @@ var gameTypeSchema = new MongooseSchema24(
1928
2215
  gameHistory: { default: [], required: true, type: [gameHistorySchema] },
1929
2216
  gameTitle: { required: true, type: String },
1930
2217
  gameType: {
1931
- enum: Object.values(import_cluemart_shared17.EnumGameType),
2218
+ enum: Object.values(import_cluemart_shared19.EnumGameType),
1932
2219
  required: true,
1933
2220
  type: String
1934
2221
  },
@@ -1936,7 +2223,7 @@ var gameTypeSchema = new MongooseSchema24(
1936
2223
  },
1937
2224
  { timestamps: true }
1938
2225
  );
1939
- var schema16 = new MongooseSchema24(
2226
+ var schema20 = new MongooseSchema24(
1940
2227
  {
1941
2228
  active: { default: false, required: true, type: Boolean },
1942
2229
  deletedAt: { default: null, required: false, type: Date },
@@ -1949,11 +2236,11 @@ var schema16 = new MongooseSchema24(
1949
2236
  },
1950
2237
  { timestamps: true }
1951
2238
  );
1952
- var GameModel = import_mongoose24.default.models.Game || import_mongoose24.default.model("Game", schema16);
2239
+ var GameModel = import_mongoose28.default.models.Game || import_mongoose28.default.model("Game", schema20);
1953
2240
 
1954
2241
  // src/mongoose/School.ts
1955
- var import_mongoose25 = __toESM(require("mongoose"));
1956
- var MongooseSchema25 = import_mongoose25.default.Schema;
2242
+ var import_mongoose29 = __toESM(require("mongoose"));
2243
+ var MongooseSchema25 = import_mongoose29.default.Schema;
1957
2244
  var campaignsSchema = new MongooseSchema25(
1958
2245
  {
1959
2246
  endDate: { required: true, type: Date },
@@ -1962,7 +2249,7 @@ var campaignsSchema = new MongooseSchema25(
1962
2249
  },
1963
2250
  { _id: false }
1964
2251
  );
1965
- var schema17 = new MongooseSchema25(
2252
+ var schema21 = new MongooseSchema25(
1966
2253
  {
1967
2254
  // New schools are active by default
1968
2255
  active: { default: false, required: true, type: Boolean },
@@ -1989,26 +2276,26 @@ var schema17 = new MongooseSchema25(
1989
2276
  },
1990
2277
  { timestamps: true }
1991
2278
  );
1992
- schema17.index(
2279
+ schema21.index(
1993
2280
  { schoolCode: 1 },
1994
2281
  {
1995
2282
  partialFilterExpression: { active: true, deletedAt: null },
1996
2283
  unique: true
1997
2284
  }
1998
2285
  );
1999
- var SchoolModel = import_mongoose25.default.models.School || import_mongoose25.default.model("School", schema17);
2286
+ var SchoolModel = import_mongoose29.default.models.School || import_mongoose29.default.model("School", schema21);
2000
2287
 
2001
2288
  // src/mongoose/Affiliate.ts
2002
- var import_cluemart_shared18 = require("@timardex/cluemart-shared");
2003
- var import_mongoose26 = __toESM(require("mongoose"));
2004
- var MongooseSchema26 = import_mongoose26.default.Schema;
2289
+ var import_cluemart_shared20 = require("@timardex/cluemart-shared");
2290
+ var import_mongoose30 = __toESM(require("mongoose"));
2291
+ var MongooseSchema26 = import_mongoose30.default.Schema;
2005
2292
  var affiliateRewardSchema = new MongooseSchema26(
2006
2293
  {
2007
2294
  createdAt: { required: true, type: Date },
2008
2295
  redeemedAt: { default: null, required: false, type: Date },
2009
2296
  rewardDescription: { required: true, type: String },
2010
2297
  rewardType: {
2011
- enum: Object.values(import_cluemart_shared18.EnumAffiliateRewardType),
2298
+ enum: Object.values(import_cluemart_shared20.EnumAffiliateRewardType),
2012
2299
  required: true,
2013
2300
  type: String
2014
2301
  },
@@ -2022,7 +2309,7 @@ var affiliateResourceSchema = new MongooseSchema26(
2022
2309
  resourceDeletedAt: { default: null, required: false, type: Date },
2023
2310
  resourceId: {
2024
2311
  required: true,
2025
- type: import_mongoose26.default.Schema.Types.ObjectId
2312
+ type: import_mongoose30.default.Schema.Types.ObjectId
2026
2313
  },
2027
2314
  resourceName: { required: true, type: String },
2028
2315
  resourceOwner: {
@@ -2030,7 +2317,7 @@ var affiliateResourceSchema = new MongooseSchema26(
2030
2317
  type: OwnerTypeSchema
2031
2318
  },
2032
2319
  resourceType: {
2033
- enum: Object.values(import_cluemart_shared18.EnumResourceType),
2320
+ enum: Object.values(import_cluemart_shared20.EnumResourceType),
2034
2321
  required: true,
2035
2322
  type: String
2036
2323
  },
@@ -2068,7 +2355,7 @@ var affiliateDetailsSchema = new MongooseSchema26(
2068
2355
  lastName: { required: true, type: String },
2069
2356
  location: { required: true, type: locationsSchema },
2070
2357
  participantType: {
2071
- enum: Object.values(import_cluemart_shared18.EnumAffiliateParticipantType),
2358
+ enum: Object.values(import_cluemart_shared20.EnumAffiliateParticipantType),
2072
2359
  required: true,
2073
2360
  type: String
2074
2361
  },
@@ -2085,7 +2372,7 @@ var redeemHistorySchema = new MongooseSchema26(
2085
2372
  },
2086
2373
  { _id: false }
2087
2374
  );
2088
- var schema18 = new MongooseSchema26(
2375
+ var schema22 = new MongooseSchema26(
2089
2376
  {
2090
2377
  active: { default: false, required: true, type: Boolean },
2091
2378
  affiliateBonusRewards: {
@@ -2115,26 +2402,26 @@ var schema18 = new MongooseSchema26(
2115
2402
  },
2116
2403
  { timestamps: true }
2117
2404
  );
2118
- schema18.index(
2405
+ schema22.index(
2119
2406
  { affiliateCode: 1 },
2120
2407
  {
2121
2408
  partialFilterExpression: { active: true, deletedAt: null },
2122
2409
  unique: true
2123
2410
  }
2124
2411
  );
2125
- var AffiliateModel = import_mongoose26.default.models.Affiliate || import_mongoose26.default.model("Affiliate", schema18);
2412
+ var AffiliateModel = import_mongoose30.default.models.Affiliate || import_mongoose30.default.model("Affiliate", schema22);
2126
2413
 
2127
2414
  // src/mongoose/Coupon.ts
2128
- var import_cluemart_shared19 = require("@timardex/cluemart-shared");
2129
- var import_mongoose27 = __toESM(require("mongoose"));
2130
- var MongooseSchema27 = import_mongoose27.default.Schema;
2415
+ var import_cluemart_shared21 = require("@timardex/cluemart-shared");
2416
+ var import_mongoose31 = __toESM(require("mongoose"));
2417
+ var MongooseSchema27 = import_mongoose31.default.Schema;
2131
2418
  var couponOptionSchema = new MongooseSchema27(
2132
2419
  {
2133
2420
  buy: { required: false, type: Number },
2134
2421
  get: { required: false, type: Number },
2135
2422
  maxRewardCount: { required: false, type: Number },
2136
2423
  type: {
2137
- enum: Object.values(import_cluemart_shared19.EnumCouponQualificationType),
2424
+ enum: Object.values(import_cluemart_shared21.EnumCouponQualificationType),
2138
2425
  required: true,
2139
2426
  type: String
2140
2427
  },
@@ -2147,20 +2434,20 @@ var couponVendorProductSchema = new MongooseSchema27(
2147
2434
  {
2148
2435
  couponId: {
2149
2436
  required: true,
2150
- type: import_mongoose27.default.Schema.Types.ObjectId
2437
+ type: import_mongoose31.default.Schema.Types.ObjectId
2151
2438
  },
2152
2439
  productId: {
2153
2440
  required: true,
2154
- type: import_mongoose27.default.Schema.Types.ObjectId
2441
+ type: import_mongoose31.default.Schema.Types.ObjectId
2155
2442
  },
2156
2443
  vendorCouponId: {
2157
2444
  required: false,
2158
- type: import_mongoose27.default.Schema.Types.ObjectId
2445
+ type: import_mongoose31.default.Schema.Types.ObjectId
2159
2446
  },
2160
2447
  vendorId: {
2161
2448
  ref: "Vendor",
2162
2449
  required: true,
2163
- type: import_mongoose27.default.Schema.Types.ObjectId
2450
+ type: import_mongoose31.default.Schema.Types.ObjectId
2164
2451
  }
2165
2452
  },
2166
2453
  { _id: false }
@@ -2182,7 +2469,7 @@ var couponParticipantUserSchema = new MongooseSchema27(
2182
2469
  userId: {
2183
2470
  ref: "User",
2184
2471
  required: true,
2185
- type: import_mongoose27.default.Schema.Types.ObjectId
2472
+ type: import_mongoose31.default.Schema.Types.ObjectId
2186
2473
  }
2187
2474
  },
2188
2475
  { timestamps: true }
@@ -2206,7 +2493,7 @@ var couponDataSchema = new MongooseSchema27(
2206
2493
  },
2207
2494
  resourceId: { required: true, type: String },
2208
2495
  resourceType: {
2209
- enum: Object.values(import_cluemart_shared19.EnumResourceType),
2496
+ enum: Object.values(import_cluemart_shared21.EnumResourceType),
2210
2497
  required: true,
2211
2498
  type: String
2212
2499
  },
@@ -2214,7 +2501,7 @@ var couponDataSchema = new MongooseSchema27(
2214
2501
  },
2215
2502
  { timestamps: true }
2216
2503
  );
2217
- var schema19 = new MongooseSchema27(
2504
+ var schema23 = new MongooseSchema27(
2218
2505
  {
2219
2506
  active: { default: true, required: true, type: Boolean },
2220
2507
  couponData: { default: [], required: false, type: [couponDataSchema] },
@@ -2226,9 +2513,9 @@ var schema19 = new MongooseSchema27(
2226
2513
  },
2227
2514
  { timestamps: true }
2228
2515
  );
2229
- schema19.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
2230
- schema19.index({ "couponData.participantUsers.userId": 1 });
2231
- var CouponModel = import_mongoose27.default.models.Coupon || import_mongoose27.default.model("Coupon", schema19);
2516
+ schema23.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
2517
+ schema23.index({ "couponData.participantUsers.userId": 1 });
2518
+ var CouponModel = import_mongoose31.default.models.Coupon || import_mongoose31.default.model("Coupon", schema23);
2232
2519
 
2233
2520
  // src/service/promoCode/constants.ts
2234
2521
  var ACTIVE_NOT_DELETED_FILTER = {
@@ -2246,7 +2533,7 @@ async function activeAffiliateCodeExists(affiliateCode) {
2246
2533
  }
2247
2534
 
2248
2535
  // src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
2249
- var import_cluemart_shared21 = require("@timardex/cluemart-shared");
2536
+ var import_cluemart_shared23 = require("@timardex/cluemart-shared");
2250
2537
  var import_utils3 = require("@timardex/cluemart-shared/utils");
2251
2538
 
2252
2539
  // src/service/saveNotificationsInDb.ts
@@ -2383,7 +2670,7 @@ async function sendPushNotifications({
2383
2670
  }
2384
2671
 
2385
2672
  // src/service/affiliate/vendorSubscriptionRewards.ts
2386
- var import_cluemart_shared20 = require("@timardex/cluemart-shared");
2673
+ var import_cluemart_shared22 = require("@timardex/cluemart-shared");
2387
2674
  var import_dayjs = __toESM(require("dayjs"));
2388
2675
  var import_timezone = __toESM(require("dayjs/plugin/timezone"));
2389
2676
  var import_utc = __toESM(require("dayjs/plugin/utc"));
@@ -2417,8 +2704,9 @@ async function getPayingStripePlanFor(userId, now, payingPlans) {
2417
2704
  if (stripe == null || stripe.subscriptionId == null) {
2418
2705
  return { hasSubscription: false, plan: null, validTypes };
2419
2706
  }
2420
- const hasActiveStatus = stripe.status === import_enums2.EnumSubscriptionStatus.ACTIVE || stripe.status === import_enums2.EnumSubscriptionStatus.TRIALING;
2421
- if (!hasActiveStatus || stripe.currentPlan == null) {
2707
+ const hasActiveStatus = stripe.status === import_enums2.EnumSubscriptionStatus.ACTIVE;
2708
+ const paidThrough = stripe.endDate ? new Date(stripe.endDate).getTime() : Number.NaN;
2709
+ if (!hasActiveStatus || !Number.isFinite(paidThrough) || paidThrough <= now.getTime() || stripe.currentPlan == null) {
2422
2710
  return { hasSubscription: false, plan: null, validTypes };
2423
2711
  }
2424
2712
  const plan = payingPlans.has(stripe.currentPlan) ? stripe.currentPlan : null;
@@ -2440,14 +2728,14 @@ import_dayjs.default.extend(import_timezone.default);
2440
2728
  var SUBSCRIPTION_REWARD_TIMEZONE = "Pacific/Auckland";
2441
2729
  async function mapVendorLicenceToSubscriptionRewardType(userId, now = /* @__PURE__ */ new Date()) {
2442
2730
  const { hasSubscription, validTypes } = await getPayingVendorStripeSubscriptionPlan(userId, now);
2443
- if (validTypes.has(import_cluemart_shared20.EnumUserLicence.PRO_VENDOR) || validTypes.has(import_cluemart_shared20.EnumUserLicence.PRO_PLUS_VENDOR)) {
2731
+ if (validTypes.has(import_cluemart_shared22.EnumUserLicence.PRO_VENDOR) || validTypes.has(import_cluemart_shared22.EnumUserLicence.PRO_PLUS_VENDOR)) {
2444
2732
  if (hasSubscription) {
2445
- return import_cluemart_shared20.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
2733
+ return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_PRO_SUBSCRIPTION;
2446
2734
  }
2447
- return import_cluemart_shared20.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2735
+ return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2448
2736
  }
2449
- if (validTypes.has(import_cluemart_shared20.EnumUserLicence.STANDARD_VENDOR)) {
2450
- return import_cluemart_shared20.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2737
+ if (validTypes.has(import_cluemart_shared22.EnumUserLicence.STANDARD_VENDOR)) {
2738
+ return import_cluemart_shared22.EnumAffiliateRewardType.ACTIVE_VENDOR_STANDARD_SUBSCRIPTION;
2451
2739
  }
2452
2740
  return null;
2453
2741
  }
@@ -2459,7 +2747,7 @@ function getSubscriptionRewardPeriodBounds(now = /* @__PURE__ */ new Date()) {
2459
2747
 
2460
2748
  // src/service/affiliate/awardAffiliateVendorSubscriptionRewards.ts
2461
2749
  function isEligibleVendorResource(resource) {
2462
- return resource.resourceType === import_cluemart_shared21.EnumResourceType.VENDOR && resource.resourceActive === true && resource.resourceDeletedAt == null;
2750
+ return resource.resourceType === import_cluemart_shared23.EnumResourceType.VENDOR && resource.resourceActive === true && resource.resourceDeletedAt == null;
2463
2751
  }
2464
2752
  async function findAffiliatesWithActiveVendorReferrals() {
2465
2753
  return await AffiliateModel.find({
@@ -2468,7 +2756,7 @@ async function findAffiliatesWithActiveVendorReferrals() {
2468
2756
  $elemMatch: {
2469
2757
  resourceActive: true,
2470
2758
  resourceDeletedAt: null,
2471
- resourceType: import_cluemart_shared21.EnumResourceType.VENDOR
2759
+ resourceType: import_cluemart_shared23.EnumResourceType.VENDOR
2472
2760
  }
2473
2761
  },
2474
2762
  deletedAt: null
@@ -2489,18 +2777,24 @@ async function isEligibleReferredVendor({
2489
2777
  async function notifyAffiliateOwnerOfSubscriptionReward({
2490
2778
  affiliateId,
2491
2779
  affiliateOwnerUserId,
2492
- resourceName,
2493
- rewardValue
2780
+ awards
2494
2781
  }) {
2782
+ if (awards.length === 0) {
2783
+ return;
2784
+ }
2785
+ const totalPoints = awards.reduce((sum, award) => sum + award.rewardValue, 0);
2786
+ const resourceNames = awards.map((award) => award.resourceName);
2787
+ const pointLabel = totalPoints === 1 ? "point" : "points";
2788
+ const message = awards.length === 1 ? `You earned ${totalPoints} ${pointLabel}! Your referred vendor "${resourceNames[0]}" has an active subscription.` : `You earned ${totalPoints} ${pointLabel}! ${awards.length} of your referred vendors have an active subscription.`;
2495
2789
  const payload = {
2496
2790
  data: {
2497
2791
  resourceId: String(affiliateId),
2498
- resourceName,
2499
- resourceType: import_cluemart_shared21.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
2792
+ resourceName: resourceNames.join(", "),
2793
+ resourceType: import_cluemart_shared23.EnumNotificationResourceType.AFFILIATE_REWARD_RECEIVED
2500
2794
  },
2501
- message: `You earned ${rewardValue} points! Your referred vendor "${resourceName}" has an active subscription.`,
2795
+ message,
2502
2796
  title: "Affiliate points earned",
2503
- type: import_cluemart_shared21.EnumNotificationType.SYSTEM,
2797
+ type: import_cluemart_shared23.EnumNotificationType.SYSTEM,
2504
2798
  userIds: [affiliateOwnerUserId]
2505
2799
  };
2506
2800
  try {
@@ -2529,7 +2823,7 @@ async function tryAwardSubscriptionReward({
2529
2823
  resourceActive: true,
2530
2824
  resourceDeletedAt: null,
2531
2825
  resourceId: resource.resourceId,
2532
- resourceType: import_cluemart_shared21.EnumResourceType.VENDOR,
2826
+ resourceType: import_cluemart_shared23.EnumResourceType.VENDOR,
2533
2827
  rewards: {
2534
2828
  $not: {
2535
2829
  $elemMatch: {
@@ -2550,15 +2844,12 @@ async function tryAwardSubscriptionReward({
2550
2844
  }
2551
2845
  ).exec();
2552
2846
  if (updateResult.modifiedCount === 0) {
2553
- return "skipped";
2847
+ return null;
2554
2848
  }
2555
- await notifyAffiliateOwnerOfSubscriptionReward({
2556
- affiliateId: affiliate._id,
2557
- affiliateOwnerUserId: affiliate.owner.userId,
2849
+ return {
2558
2850
  resourceName: resource.resourceName,
2559
2851
  rewardValue: reward.rewardValue
2560
- });
2561
- return "awarded";
2852
+ };
2562
2853
  }
2563
2854
  async function processAffiliateVendorReferral({
2564
2855
  affiliate,
@@ -2572,14 +2863,14 @@ async function processAffiliateVendorReferral({
2572
2863
  resourceOwnerUserId: resource.resourceOwner.userId
2573
2864
  });
2574
2865
  if (!vendorEligible) {
2575
- return "skipped";
2866
+ return null;
2576
2867
  }
2577
2868
  const rewardType = await mapVendorLicenceToSubscriptionRewardType(
2578
2869
  resource.resourceOwner.userId,
2579
2870
  now
2580
2871
  );
2581
2872
  if (!rewardType) {
2582
- return "skipped";
2873
+ return null;
2583
2874
  }
2584
2875
  return tryAwardSubscriptionReward({
2585
2876
  affiliate,
@@ -2595,8 +2886,9 @@ async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new
2595
2886
  const affiliates = await findAffiliatesWithActiveVendorReferrals();
2596
2887
  let awarded = 0;
2597
2888
  let skipped = 0;
2598
- const seenPairs = /* @__PURE__ */ new Set();
2599
2889
  for (const affiliate of affiliates) {
2890
+ const awards = [];
2891
+ const seenPairs = /* @__PURE__ */ new Set();
2600
2892
  for (const resource of affiliate.affiliateResources) {
2601
2893
  if (!isEligibleVendorResource(resource)) {
2602
2894
  continue;
@@ -2606,19 +2898,27 @@ async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new
2606
2898
  continue;
2607
2899
  }
2608
2900
  seenPairs.add(pairKey);
2609
- const outcome = await processAffiliateVendorReferral({
2901
+ const award = await processAffiliateVendorReferral({
2610
2902
  affiliate,
2611
2903
  createdAt,
2612
2904
  now,
2613
2905
  period,
2614
2906
  resource
2615
2907
  });
2616
- if (outcome === "awarded") {
2908
+ if (award) {
2617
2909
  awarded += 1;
2910
+ awards.push(award);
2618
2911
  } else {
2619
2912
  skipped += 1;
2620
2913
  }
2621
2914
  }
2915
+ if (awards.length > 0) {
2916
+ await notifyAffiliateOwnerOfSubscriptionReward({
2917
+ affiliateId: affiliate._id,
2918
+ affiliateOwnerUserId: affiliate.owner.userId,
2919
+ awards
2920
+ });
2921
+ }
2622
2922
  }
2623
2923
  return { awarded, skipped };
2624
2924
  }
@@ -2644,7 +2944,7 @@ function normalizeAffiliatePromoCodes(promoCodes) {
2644
2944
  }
2645
2945
 
2646
2946
  // src/service/database.ts
2647
- var import_mongoose31 = __toESM(require("mongoose"));
2947
+ var import_mongoose35 = __toESM(require("mongoose"));
2648
2948
  var connectToDatabase = async ({
2649
2949
  appName,
2650
2950
  dbName,
@@ -2657,7 +2957,7 @@ var connectToDatabase = async ({
2657
2957
  // Fallback to MongoDB Atlas connection string
2658
2958
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
2659
2959
  );
2660
- await import_mongoose31.default.connect(mongoUri);
2960
+ await import_mongoose35.default.connect(mongoUri);
2661
2961
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
2662
2962
  console.log(
2663
2963
  `${connectionType} connected from server/src/service/database.ts`
@@ -2670,7 +2970,7 @@ var connectToDatabase = async ({
2670
2970
 
2671
2971
  // src/types/index.ts
2672
2972
  var import_express = __toESM(require("express"));
2673
- var import_mongoose32 = __toESM(require("mongoose"));
2973
+ var import_mongoose36 = __toESM(require("mongoose"));
2674
2974
 
2675
2975
  // src/service/notifyUsers.ts
2676
2976
  async function publishNotificationEvents(userId, pubsub) {
@@ -2718,7 +3018,7 @@ async function notifyUsers({
2718
3018
  }
2719
3019
 
2720
3020
  // src/service/updateAdStatus.ts
2721
- var import_cluemart_shared22 = require("@timardex/cluemart-shared");
3021
+ var import_cluemart_shared24 = require("@timardex/cluemart-shared");
2722
3022
  async function updateAdStatuses() {
2723
3023
  const now = /* @__PURE__ */ new Date();
2724
3024
  const invalidResult = await AdModel.updateMany(
@@ -2728,41 +3028,66 @@ async function updateAdStatuses() {
2728
3028
  { end: { $exists: false } },
2729
3029
  { $expr: { $gt: ["$start", "$end"] } }
2730
3030
  ],
2731
- status: { $ne: import_cluemart_shared22.EnumAdStatus.PAUSED }
3031
+ status: { $ne: import_cluemart_shared24.EnumAdStatus.PAUSED }
2732
3032
  },
2733
- { $set: { status: import_cluemart_shared22.EnumAdStatus.PAUSED } }
3033
+ { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
2734
3034
  );
2735
3035
  const expiredResult = await AdModel.updateMany(
2736
- { end: { $lte: now }, status: { $ne: import_cluemart_shared22.EnumAdStatus.EXPIRED } },
2737
- { $set: { status: import_cluemart_shared22.EnumAdStatus.EXPIRED } }
3036
+ { end: { $lte: now }, status: { $ne: import_cluemart_shared24.EnumAdStatus.EXPIRED } },
3037
+ { $set: { status: import_cluemart_shared24.EnumAdStatus.EXPIRED } }
3038
+ );
3039
+ const eligibleBooking = {
3040
+ $or: [
3041
+ { bookingKind: { $exists: false } },
3042
+ { bookingKind: null },
3043
+ {
3044
+ approvalStatus: import_cluemart_shared24.EnumAdApprovalStatus.APPROVED,
3045
+ bookingKind: import_cluemart_shared24.EnumAdBookingSlotKind.RESERVED
3046
+ },
3047
+ {
3048
+ approvalStatus: import_cluemart_shared24.EnumAdApprovalStatus.APPROVED,
3049
+ bookingKind: import_cluemart_shared24.EnumAdBookingSlotKind.PAID,
3050
+ paymentStatus: import_cluemart_shared24.EnumAdPaymentStatus.PAID
3051
+ }
3052
+ ]
3053
+ };
3054
+ const awaitingApprovalResult = await AdModel.updateMany(
3055
+ {
3056
+ $nor: eligibleBooking.$or,
3057
+ bookingKind: { $in: Object.values(import_cluemart_shared24.EnumAdBookingSlotKind) },
3058
+ end: { $gt: now },
3059
+ status: import_cluemart_shared24.EnumAdStatus.ACTIVE
3060
+ },
3061
+ { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
2738
3062
  );
2739
3063
  const activeResult = await AdModel.updateMany(
2740
3064
  {
2741
3065
  end: { $gt: now },
2742
3066
  start: { $lte: now },
2743
- status: { $ne: import_cluemart_shared22.EnumAdStatus.ACTIVE }
3067
+ status: { $ne: import_cluemart_shared24.EnumAdStatus.ACTIVE },
3068
+ ...eligibleBooking
2744
3069
  },
2745
- { $set: { status: import_cluemart_shared22.EnumAdStatus.ACTIVE } }
3070
+ { $set: { status: import_cluemart_shared24.EnumAdStatus.ACTIVE } }
2746
3071
  );
2747
3072
  const pausedResult = await AdModel.updateMany(
2748
- { start: { $gt: now }, status: { $ne: import_cluemart_shared22.EnumAdStatus.PAUSED } },
2749
- { $set: { status: import_cluemart_shared22.EnumAdStatus.PAUSED } }
3073
+ { start: { $gt: now }, status: { $ne: import_cluemart_shared24.EnumAdStatus.PAUSED } },
3074
+ { $set: { status: import_cluemart_shared24.EnumAdStatus.PAUSED } }
2750
3075
  );
2751
3076
  console.log(
2752
- `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
3077
+ `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
2753
3078
  );
2754
3079
  }
2755
3080
 
2756
3081
  // src/service/objectIdToString.ts
2757
- var import_mongoose34 = __toESM(require("mongoose"));
3082
+ var import_mongoose38 = __toESM(require("mongoose"));
2758
3083
  function isValidObjectId(value) {
2759
- return import_mongoose34.default.Types.ObjectId.isValid(value);
3084
+ return import_mongoose38.default.Types.ObjectId.isValid(value);
2760
3085
  }
2761
3086
  function convertObjectIdsToStrings(obj) {
2762
3087
  if (obj === null || obj === void 0) {
2763
3088
  return obj;
2764
3089
  }
2765
- if (obj instanceof import_mongoose34.default.Types.ObjectId) {
3090
+ if (obj instanceof import_mongoose38.default.Types.ObjectId) {
2766
3091
  return obj.toString();
2767
3092
  }
2768
3093
  if (obj instanceof Date) {
@@ -2782,7 +3107,7 @@ function convertObjectIdsToStrings(obj) {
2782
3107
  }
2783
3108
 
2784
3109
  // src/service/event/updateAllEventDateTimeStatuses.ts
2785
- var import_cluemart_shared23 = require("@timardex/cluemart-shared");
3110
+ var import_cluemart_shared25 = require("@timardex/cluemart-shared");
2786
3111
  var import_dayjs2 = __toESM(require("dayjs"));
2787
3112
  var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
2788
3113
  var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
@@ -2791,24 +3116,24 @@ import_dayjs2.default.extend(import_isoWeek.default);
2791
3116
  function getFutureEventStatus(startDateTime, now) {
2792
3117
  const hoursUntilStart = startDateTime.diff(now, "hour", true);
2793
3118
  if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
2794
- return import_cluemart_shared23.EnumEventDateStatus.STARTING_SOON;
3119
+ return import_cluemart_shared25.EnumEventDateStatus.STARTING_SOON;
2795
3120
  }
2796
3121
  if (startDateTime.isSame(now, "day")) {
2797
- return import_cluemart_shared23.EnumEventDateStatus.TODAY;
3122
+ return import_cluemart_shared25.EnumEventDateStatus.TODAY;
2798
3123
  }
2799
3124
  if (startDateTime.isSame(now.add(1, "day"), "day")) {
2800
- return import_cluemart_shared23.EnumEventDateStatus.TOMORROW;
3125
+ return import_cluemart_shared25.EnumEventDateStatus.TOMORROW;
2801
3126
  }
2802
3127
  if (startDateTime.isSame(now, "isoWeek")) {
2803
- return import_cluemart_shared23.EnumEventDateStatus.THIS_WEEK;
3128
+ return import_cluemart_shared25.EnumEventDateStatus.THIS_WEEK;
2804
3129
  }
2805
3130
  if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
2806
- return import_cluemart_shared23.EnumEventDateStatus.NEXT_WEEK;
3131
+ return import_cluemart_shared25.EnumEventDateStatus.NEXT_WEEK;
2807
3132
  }
2808
- return import_cluemart_shared23.EnumEventDateStatus.UPCOMING;
3133
+ return import_cluemart_shared25.EnumEventDateStatus.UPCOMING;
2809
3134
  }
2810
3135
  function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
2811
- const dateTimeFormat = `${import_cluemart_shared23.dateFormat} ${import_cluemart_shared23.timeFormat}`;
3136
+ const dateTimeFormat = `${import_cluemart_shared25.dateFormat} ${import_cluemart_shared25.timeFormat}`;
2812
3137
  const startDateTime = (0, import_dayjs2.default)(
2813
3138
  `${dateTime.startDate} ${dateTime.startTime}`,
2814
3139
  dateTimeFormat,
@@ -2822,13 +3147,13 @@ function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()
2822
3147
  if (!startDateTime.isValid() || !endDateTime.isValid()) {
2823
3148
  return {
2824
3149
  ...dateTime,
2825
- dateStatus: import_cluemart_shared23.EnumEventDateStatus.INVALID
3150
+ dateStatus: import_cluemart_shared25.EnumEventDateStatus.INVALID
2826
3151
  };
2827
3152
  }
2828
3153
  if (endDateTime.isBefore(startDateTime)) {
2829
3154
  return {
2830
3155
  ...dateTime,
2831
- dateStatus: import_cluemart_shared23.EnumEventDateStatus.INVALID
3156
+ dateStatus: import_cluemart_shared25.EnumEventDateStatus.INVALID
2832
3157
  };
2833
3158
  }
2834
3159
  let dateStatus;
@@ -2836,10 +3161,10 @@ function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()
2836
3161
  if (startDateTime.isAfter(now)) {
2837
3162
  dateStatus = getFutureEventStatus(startDateTime, now);
2838
3163
  } else {
2839
- dateStatus = import_cluemart_shared23.EnumEventDateStatus.STARTED;
3164
+ dateStatus = import_cluemart_shared25.EnumEventDateStatus.STARTED;
2840
3165
  }
2841
3166
  } else {
2842
- dateStatus = import_cluemart_shared23.EnumEventDateStatus.ENDED;
3167
+ dateStatus = import_cluemart_shared25.EnumEventDateStatus.ENDED;
2843
3168
  }
2844
3169
  return {
2845
3170
  ...dateTime,
@@ -2923,7 +3248,7 @@ async function findEventOrImportedMarketById(resourceId) {
2923
3248
  }
2924
3249
 
2925
3250
  // src/service/relations.ts
2926
- var import_cluemart_shared24 = require("@timardex/cluemart-shared");
3251
+ var import_cluemart_shared26 = require("@timardex/cluemart-shared");
2927
3252
  function didRemoveAnyEventDates(previousDateTime, nextDateTime) {
2928
3253
  if (!previousDateTime?.length) {
2929
3254
  return false;
@@ -2941,7 +3266,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
2941
3266
  ) ?? false;
2942
3267
  return {
2943
3268
  ...relationDate,
2944
- status: existsInEvent ? relationDate.status : import_cluemart_shared24.EnumInviteStatus.UNAVAILABLE
3269
+ status: existsInEvent ? relationDate.status : import_cluemart_shared26.EnumInviteStatus.UNAVAILABLE
2945
3270
  };
2946
3271
  });
2947
3272
  }
@@ -2950,15 +3275,15 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
2950
3275
  var import_dayjs6 = __toESM(require("dayjs"));
2951
3276
 
2952
3277
  // src/service/license/compliance/utils.ts
2953
- var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3278
+ var import_cluemart_shared31 = require("@timardex/cluemart-shared");
2954
3279
  var import_dayjs5 = __toESM(require("dayjs"));
2955
3280
 
2956
3281
  // src/service/license/compliance/event.ts
2957
- var import_cluemart_shared25 = require("@timardex/cluemart-shared");
3282
+ var import_cluemart_shared27 = require("@timardex/cluemart-shared");
2958
3283
  var eventLicences = [
2959
- import_cluemart_shared25.EnumUserLicence.STANDARD_EVENT,
2960
- import_cluemart_shared25.EnumUserLicence.PRO_EVENT,
2961
- import_cluemart_shared25.EnumUserLicence.PRO_PLUS_EVENT
3284
+ import_cluemart_shared27.EnumUserLicence.STANDARD_EVENT,
3285
+ import_cluemart_shared27.EnumUserLicence.PRO_EVENT,
3286
+ import_cluemart_shared27.EnumUserLicence.PRO_PLUS_EVENT
2962
3287
  ];
2963
3288
  async function handleEventLicenceCompliance(user, now) {
2964
3289
  if (!user.licences || !user.events?.length) {
@@ -3170,9 +3495,9 @@ function buildLicenceExpiryPipeline(params) {
3170
3495
  }
3171
3496
 
3172
3497
  // src/service/license/compliance/partner.ts
3173
- var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3498
+ var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3174
3499
  var partnerLicences = [
3175
- import_cluemart_shared26.EnumUserLicence.STANDARD_PARTNER
3500
+ import_cluemart_shared28.EnumUserLicence.STANDARD_PARTNER
3176
3501
  ];
3177
3502
  async function handlePartnerLicenceCompliance(user, now) {
3178
3503
  if (!user.licences || !user.partner) {
@@ -3182,17 +3507,19 @@ async function handlePartnerLicenceCompliance(user, now) {
3182
3507
  }
3183
3508
 
3184
3509
  // src/service/license/compliance/vendor.ts
3185
- var import_cluemart_shared28 = require("@timardex/cluemart-shared");
3510
+ var import_cluemart_shared30 = require("@timardex/cluemart-shared");
3186
3511
  var import_dayjs4 = __toESM(require("dayjs"));
3187
3512
 
3188
3513
  // src/service/license/models.ts
3189
- var import_cluemart_shared27 = require("@timardex/cluemart-shared");
3514
+ var import_cluemart_shared29 = require("@timardex/cluemart-shared");
3190
3515
  var import_dayjs3 = __toESM(require("dayjs"));
3191
3516
  var import_graphql = require("graphql");
3192
3517
  var LicenceExpiryDate = /* @__PURE__ */ ((LicenceExpiryDate2) => {
3193
3518
  LicenceExpiryDate2["ONE_YEAR"] = "1 year";
3194
3519
  LicenceExpiryDate2["ONE_MONTH"] = "1 month";
3195
3520
  LicenceExpiryDate2["TWO_MONTHS"] = "2 months";
3521
+ LicenceExpiryDate2["THREE_MONTHS"] = "3 months";
3522
+ LicenceExpiryDate2["SIX_MONTHS"] = "6 months";
3196
3523
  return LicenceExpiryDate2;
3197
3524
  })(LicenceExpiryDate || {});
3198
3525
  var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
@@ -3204,31 +3531,31 @@ var LicenceCategory = /* @__PURE__ */ ((LicenceCategory2) => {
3204
3531
  return LicenceCategory2;
3205
3532
  })(LicenceCategory || {});
3206
3533
  var licenceCategoryMapping = {
3207
- [import_cluemart_shared27.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
3208
- [import_cluemart_shared27.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
3209
- [import_cluemart_shared27.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
3210
- [import_cluemart_shared27.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
3211
- [import_cluemart_shared27.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
3212
- [import_cluemart_shared27.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
3213
- [import_cluemart_shared27.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
3214
- [import_cluemart_shared27.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
3215
- [import_cluemart_shared27.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
3534
+ [import_cluemart_shared29.EnumUserLicence.PRO_EVENT]: "event" /* EVENT */,
3535
+ [import_cluemart_shared29.EnumUserLicence.PRO_PLUS_EVENT]: "event" /* EVENT */,
3536
+ [import_cluemart_shared29.EnumUserLicence.PRO_PLUS_VENDOR]: "vendor" /* VENDOR */,
3537
+ [import_cluemart_shared29.EnumUserLicence.PRO_VENDOR]: "vendor" /* VENDOR */,
3538
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT]: "event" /* EVENT */,
3539
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_PARTNER]: "partner" /* PARTNER */,
3540
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_VENDOR]: "vendor" /* VENDOR */,
3541
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_AFFILIATE]: "affiliate" /* AFFILIATE */,
3542
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_SCHOOL]: "school" /* SCHOOL */
3216
3543
  };
3217
3544
  var licencePriority = {
3218
- [import_cluemart_shared27.EnumUserLicence.PRO_PLUS_EVENT]: 3,
3219
- [import_cluemart_shared27.EnumUserLicence.PRO_EVENT]: 2,
3220
- [import_cluemart_shared27.EnumUserLicence.STANDARD_EVENT]: 1,
3221
- [import_cluemart_shared27.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
3222
- [import_cluemart_shared27.EnumUserLicence.PRO_VENDOR]: 2,
3223
- [import_cluemart_shared27.EnumUserLicence.STANDARD_VENDOR]: 1,
3224
- [import_cluemart_shared27.EnumUserLicence.STANDARD_PARTNER]: 1,
3225
- [import_cluemart_shared27.EnumUserLicence.STANDARD_AFFILIATE]: 1,
3226
- [import_cluemart_shared27.EnumUserLicence.STANDARD_SCHOOL]: 1
3545
+ [import_cluemart_shared29.EnumUserLicence.PRO_PLUS_EVENT]: 3,
3546
+ [import_cluemart_shared29.EnumUserLicence.PRO_EVENT]: 2,
3547
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT]: 1,
3548
+ [import_cluemart_shared29.EnumUserLicence.PRO_PLUS_VENDOR]: 3,
3549
+ [import_cluemart_shared29.EnumUserLicence.PRO_VENDOR]: 2,
3550
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_VENDOR]: 1,
3551
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_PARTNER]: 1,
3552
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_AFFILIATE]: 1,
3553
+ [import_cluemart_shared29.EnumUserLicence.STANDARD_SCHOOL]: 1
3227
3554
  };
3228
3555
  var standardLicences = [
3229
- import_cluemart_shared27.EnumUserLicence.STANDARD_VENDOR,
3230
- import_cluemart_shared27.EnumUserLicence.STANDARD_EVENT,
3231
- import_cluemart_shared27.EnumUserLicence.STANDARD_PARTNER
3556
+ import_cluemart_shared29.EnumUserLicence.STANDARD_VENDOR,
3557
+ import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT,
3558
+ import_cluemart_shared29.EnumUserLicence.STANDARD_PARTNER
3232
3559
  ];
3233
3560
  var standardLicenceSet = new Set(standardLicences);
3234
3561
  function isStandardLicence(licence) {
@@ -3242,11 +3569,11 @@ var categoryRegexMapping = {
3242
3569
  ["school" /* SCHOOL */]: /_school$/
3243
3570
  };
3244
3571
  var categoryFallbackLicence = {
3245
- ["event" /* EVENT */]: import_cluemart_shared27.EnumUserLicence.STANDARD_EVENT,
3246
- ["partner" /* PARTNER */]: import_cluemart_shared27.EnumUserLicence.STANDARD_PARTNER,
3247
- ["vendor" /* VENDOR */]: import_cluemart_shared27.EnumUserLicence.STANDARD_VENDOR,
3248
- ["affiliate" /* AFFILIATE */]: import_cluemart_shared27.EnumUserLicence.STANDARD_AFFILIATE,
3249
- ["school" /* SCHOOL */]: import_cluemart_shared27.EnumUserLicence.STANDARD_SCHOOL
3572
+ ["event" /* EVENT */]: import_cluemart_shared29.EnumUserLicence.STANDARD_EVENT,
3573
+ ["partner" /* PARTNER */]: import_cluemart_shared29.EnumUserLicence.STANDARD_PARTNER,
3574
+ ["vendor" /* VENDOR */]: import_cluemart_shared29.EnumUserLicence.STANDARD_VENDOR,
3575
+ ["affiliate" /* AFFILIATE */]: import_cluemart_shared29.EnumUserLicence.STANDARD_AFFILIATE,
3576
+ ["school" /* SCHOOL */]: import_cluemart_shared29.EnumUserLicence.STANDARD_SCHOOL
3250
3577
  };
3251
3578
  var LicenceFilterInput = {
3252
3579
  INPUT_USER_LICENCES: "$licences"
@@ -3278,7 +3605,9 @@ function createLicenceObject(expiryDate, licenceType) {
3278
3605
  const expiryDateMapping = {
3279
3606
  ["1 year" /* ONE_YEAR */]: today.add(1, "year").endOf("day").toDate(),
3280
3607
  ["1 month" /* ONE_MONTH */]: today.add(1, "month").endOf("day").toDate(),
3281
- ["2 months" /* TWO_MONTHS */]: today.add(2, "month").endOf("day").toDate()
3608
+ ["2 months" /* TWO_MONTHS */]: today.add(2, "month").endOf("day").toDate(),
3609
+ ["3 months" /* THREE_MONTHS */]: today.add(3, "month").endOf("day").toDate(),
3610
+ ["6 months" /* SIX_MONTHS */]: today.add(6, "month").endOf("day").toDate()
3282
3611
  };
3283
3612
  const licenceObject = {
3284
3613
  expiryDate: expiryDateMapping[expiryDate],
@@ -3382,13 +3711,13 @@ async function checkOwnerHasLicence({
3382
3711
  const owner = await UserModel.findById(userId);
3383
3712
  if (!owner) throw new import_graphql.GraphQLError("Owner not found");
3384
3713
  const categoryByResource = {
3385
- [import_cluemart_shared27.EnumResourceType.EVENT]: "event" /* EVENT */,
3386
- [import_cluemart_shared27.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
3387
- [import_cluemart_shared27.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
3388
- [import_cluemart_shared27.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
3389
- [import_cluemart_shared27.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
3714
+ [import_cluemart_shared29.EnumResourceType.EVENT]: "event" /* EVENT */,
3715
+ [import_cluemart_shared29.EnumResourceType.PARTNER]: "partner" /* PARTNER */,
3716
+ [import_cluemart_shared29.EnumResourceType.VENDOR]: "vendor" /* VENDOR */,
3717
+ [import_cluemart_shared29.EnumResourceType.AFFILIATE]: "affiliate" /* AFFILIATE */,
3718
+ [import_cluemart_shared29.EnumResourceType.SCHOOL]: "school" /* SCHOOL */
3390
3719
  };
3391
- if (!(0, import_cluemart_shared27.isNonVisitorResourceType)(resourceType)) {
3720
+ if (!(0, import_cluemart_shared29.isNonVisitorResourceType)(resourceType)) {
3392
3721
  throw new import_graphql.GraphQLError(`Invalid resource type: ${resourceType}.`);
3393
3722
  }
3394
3723
  const requiredCategory = categoryByResource[resourceType];
@@ -3425,7 +3754,9 @@ async function findUserVendor(userId, logLabel) {
3425
3754
  "owner.userId": userId
3426
3755
  }).lean().exec();
3427
3756
  if (!vendor) {
3428
- console.warn(`[${logLabel}] Vendor not found for id=${user.vendor}`);
3757
+ console.warn(
3758
+ `[${logLabel}] Vendor not found for id=${user.vendor}, userId=${userId}`
3759
+ );
3429
3760
  return null;
3430
3761
  }
3431
3762
  return vendor;
@@ -3466,7 +3797,7 @@ async function applyVendorDowngrade(vendor, ownerUserId) {
3466
3797
  return (result?.matchedCount ?? 0) > 0;
3467
3798
  }
3468
3799
  async function downgradeVendorProFeatures(userId, licenceType) {
3469
- const isStandardVendor = licenceType === import_cluemart_shared28.EnumUserLicence.STANDARD_VENDOR;
3800
+ const isStandardVendor = licenceType === import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR;
3470
3801
  if (!isStandardVendor) {
3471
3802
  return;
3472
3803
  }
@@ -3478,6 +3809,7 @@ async function downgradeVendorProFeatures(userId, licenceType) {
3478
3809
  await applyVendorDowngrade(vendor, userId);
3479
3810
  } catch (error) {
3480
3811
  console.error("[downgradeVendorProFeatures] Failed:", error);
3812
+ throw error;
3481
3813
  }
3482
3814
  }
3483
3815
  async function applyVendorRestore(vendor, ownerUserId) {
@@ -3512,7 +3844,7 @@ async function applyVendorRestore(vendor, ownerUserId) {
3512
3844
  return (result?.matchedCount ?? 0) > 0;
3513
3845
  }
3514
3846
  async function restoreVendorProFeatures(userId, licenceType) {
3515
- const isProVendor = licenceType === import_cluemart_shared28.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared28.EnumUserLicence.PRO_PLUS_VENDOR;
3847
+ const isProVendor = licenceType === import_cluemart_shared30.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR;
3516
3848
  if (!isProVendor) {
3517
3849
  return;
3518
3850
  }
@@ -3524,23 +3856,35 @@ async function restoreVendorProFeatures(userId, licenceType) {
3524
3856
  await applyVendorRestore(vendor, userId);
3525
3857
  } catch (error) {
3526
3858
  console.error("[restoreVendorProFeatures] Failed:", error);
3859
+ throw error;
3527
3860
  }
3528
3861
  }
3529
3862
  var vendorLicences = [
3530
- import_cluemart_shared28.EnumUserLicence.STANDARD_VENDOR,
3531
- import_cluemart_shared28.EnumUserLicence.PRO_VENDOR,
3532
- import_cluemart_shared28.EnumUserLicence.PRO_PLUS_VENDOR
3863
+ import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR,
3864
+ import_cluemart_shared30.EnumUserLicence.PRO_VENDOR,
3865
+ import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR
3533
3866
  ];
3534
3867
  function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
3535
3868
  const stripe = user.stripe;
3536
- if (!stripe?.subscriptionId || stripe.currentPlan !== licenceType || stripe.status !== import_cluemart_shared28.EnumSubscriptionStatus.ACTIVE && stripe.status !== import_cluemart_shared28.EnumSubscriptionStatus.TRIALING) {
3869
+ if (!stripe || stripe.currentPlan !== licenceType) {
3537
3870
  return false;
3538
3871
  }
3539
- if (stripe.cancelAtPeriodEnd !== true || !stripe.endDate) {
3872
+ const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? (0, import_dayjs4.default)(stripe.paymentGracePeriodEndsAt) : null;
3873
+ const hasActivePaymentGracePeriod = (stripe.status === import_cluemart_shared30.EnumSubscriptionStatus.PAST_DUE || stripe.status === import_cluemart_shared30.EnumSubscriptionStatus.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
3874
+ if (hasActivePaymentGracePeriod) {
3540
3875
  return true;
3541
3876
  }
3877
+ if (!stripe.subscriptionId) {
3878
+ return false;
3879
+ }
3880
+ if (stripe.status !== import_cluemart_shared30.EnumSubscriptionStatus.ACTIVE) {
3881
+ return false;
3882
+ }
3883
+ if (!stripe.endDate) {
3884
+ return false;
3885
+ }
3542
3886
  const paidThrough = (0, import_dayjs4.default)(stripe.endDate);
3543
- return !paidThrough.isValid() || paidThrough.isAfter(now);
3887
+ return paidThrough.isValid() && paidThrough.isAfter(now);
3544
3888
  }
3545
3889
  async function handleVendorLicenceCompliance(user, now) {
3546
3890
  if (!user.licences || !user.vendor) {
@@ -3553,7 +3897,7 @@ async function handleVendorLicenceCompliance(user, now) {
3553
3897
  return;
3554
3898
  }
3555
3899
  const proLicences = vendorLicencesOfUser.filter(
3556
- (licence) => licence.licenceType !== import_cluemart_shared28.EnumUserLicence.STANDARD_VENDOR
3900
+ (licence) => licence.licenceType !== import_cluemart_shared30.EnumUserLicence.STANDARD_VENDOR
3557
3901
  );
3558
3902
  const expiredProLicences = proLicences.filter(
3559
3903
  (licence) => !(0, import_dayjs4.default)(licence.expiryDate).isAfter(now)
@@ -3597,11 +3941,11 @@ async function handleVendorLicenceCompliance(user, now) {
3597
3941
  data: {
3598
3942
  resourceId: String(vendor._id),
3599
3943
  resourceName: vendor.name,
3600
- resourceType: import_cluemart_shared28.EnumNotificationResourceType.DOWNGRADED_VENDOR
3944
+ resourceType: import_cluemart_shared30.EnumNotificationResourceType.DOWNGRADED_VENDOR
3601
3945
  },
3602
3946
  message: `Your Vendor license has been downgraded due to licence expiration.`,
3603
3947
  title: `Vendor License Downgraded`,
3604
- type: import_cluemart_shared28.EnumNotificationType.SYSTEM,
3948
+ type: import_cluemart_shared30.EnumNotificationType.SYSTEM,
3605
3949
  userIds: [user._id]
3606
3950
  };
3607
3951
  await sendDeactivationNotification(payload, user._id, vendor.name, "vendor");
@@ -3615,12 +3959,26 @@ async function vendorOwnerHasProLicence(vendorId) {
3615
3959
  if (!vendor) {
3616
3960
  return false;
3617
3961
  }
3618
- const owner = await UserModel.findById(vendor.owner.userId, { licences: 1 }).lean().exec();
3962
+ const owner = await UserModel.findById(vendor.owner.userId, {
3963
+ licences: 1,
3964
+ stripe: 1
3965
+ }).lean().exec();
3966
+ if (!owner) {
3967
+ return false;
3968
+ }
3969
+ const now = (0, import_dayjs4.default)();
3970
+ const effectiveVendorLicences = owner.licences?.filter(
3971
+ (licence) => licence?.licenceType && ((0, import_dayjs4.default)(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
3972
+ owner,
3973
+ licence.licenceType,
3974
+ now
3975
+ ))
3976
+ );
3619
3977
  const highestVendorLicence = getHighestLicenceForCategory(
3620
- owner?.licences,
3978
+ effectiveVendorLicences,
3621
3979
  "vendor" /* VENDOR */
3622
3980
  );
3623
- return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared28.EnumUserLicence.PRO_VENDOR];
3981
+ return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[import_cluemart_shared30.EnumUserLicence.PRO_VENDOR];
3624
3982
  }
3625
3983
 
3626
3984
  // src/service/license/compliance/utils.ts
@@ -3630,12 +3988,12 @@ async function syncUserLicencesAfterExpiry(userId, licenceTypes, now, mode = "do
3630
3988
  const pipeline = buildLicenceExpiryPipeline({
3631
3989
  downgradeBranches: [
3632
3990
  {
3633
- case: import_cluemart_shared29.EnumUserLicence.PRO_PLUS_VENDOR,
3634
- then: import_cluemart_shared29.EnumUserLicence.STANDARD_VENDOR
3991
+ case: import_cluemart_shared31.EnumUserLicence.PRO_PLUS_VENDOR,
3992
+ then: import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR
3635
3993
  },
3636
3994
  {
3637
- case: import_cluemart_shared29.EnumUserLicence.PRO_VENDOR,
3638
- then: import_cluemart_shared29.EnumUserLicence.STANDARD_VENDOR
3995
+ case: import_cluemart_shared31.EnumUserLicence.PRO_VENDOR,
3996
+ then: import_cluemart_shared31.EnumUserLicence.STANDARD_VENDOR
3639
3997
  }
3640
3998
  ],
3641
3999
  licenceTypes,
@@ -3764,7 +4122,7 @@ var REMINDER_WINDOW_MIN_HOURS = 6.5 * 24;
3764
4122
  var REMINDER_WINDOW_MAX_HOURS = 7.5 * 24;
3765
4123
 
3766
4124
  // src/service/license/reminder/utils.ts
3767
- var import_cluemart_shared30 = require("@timardex/cluemart-shared");
4125
+ var import_cluemart_shared32 = require("@timardex/cluemart-shared");
3768
4126
  var import_utils8 = require("@timardex/cluemart-shared/utils");
3769
4127
  var import_dayjs7 = __toESM(require("dayjs"));
3770
4128
 
@@ -3830,24 +4188,24 @@ function isLicenseExpiringIn7Days(expiryDate, now) {
3830
4188
  return hoursUntilExpiry >= REMINDER_WINDOW_MIN_HOURS && hoursUntilExpiry <= REMINDER_WINDOW_MAX_HOURS;
3831
4189
  }
3832
4190
  function getLicenseName(licenceType) {
3833
- return import_cluemart_shared30.licenseNiceNames[licenceType] || licenceType;
4191
+ return import_cluemart_shared32.licenseNiceNames[licenceType] || licenceType;
3834
4192
  }
3835
4193
  function getNotificationTypes(isVendorLicense, isPartnerLicense) {
3836
4194
  if (isVendorLicense) {
3837
4195
  return {
3838
- notificationType: import_cluemart_shared30.EnumNotificationType.SYSTEM,
3839
- resourceType: import_cluemart_shared30.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
4196
+ notificationType: import_cluemart_shared32.EnumNotificationType.SYSTEM,
4197
+ resourceType: import_cluemart_shared32.EnumNotificationResourceType.EXPIRATION_REMINDER_VENDOR
3840
4198
  };
3841
4199
  }
3842
4200
  if (isPartnerLicense) {
3843
4201
  return {
3844
- notificationType: import_cluemart_shared30.EnumNotificationType.SYSTEM,
3845
- resourceType: import_cluemart_shared30.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
4202
+ notificationType: import_cluemart_shared32.EnumNotificationType.SYSTEM,
4203
+ resourceType: import_cluemart_shared32.EnumNotificationResourceType.EXPIRATION_REMINDER_PARTNER
3846
4204
  };
3847
4205
  }
3848
4206
  return {
3849
- notificationType: import_cluemart_shared30.EnumNotificationType.SYSTEM,
3850
- resourceType: import_cluemart_shared30.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
4207
+ notificationType: import_cluemart_shared32.EnumNotificationType.SYSTEM,
4208
+ resourceType: import_cluemart_shared32.EnumNotificationResourceType.EXPIRATION_REMINDER_EVENT
3851
4209
  };
3852
4210
  }
3853
4211
  async function getLicenseResourceInfo(user, licence) {
@@ -3899,11 +4257,11 @@ async function getLicenseResourceInfo(user, licence) {
3899
4257
  };
3900
4258
  }
3901
4259
  function getLicenceExpiryMode(licenceType) {
3902
- return licenceType === import_cluemart_shared30.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared30.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
4260
+ return licenceType === import_cluemart_shared32.EnumUserLicence.PRO_VENDOR || licenceType === import_cluemart_shared32.EnumUserLicence.PRO_PLUS_VENDOR ? "downgrade" : "extend";
3903
4261
  }
3904
4262
  async function sendLicenseReminder(user, licence) {
3905
4263
  const licenceName = getLicenseName(licence.licenceType);
3906
- const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared30.dateFormat);
4264
+ const expiryDate = (0, import_dayjs7.default)(licence.expiryDate).format(import_cluemart_shared32.dateFormat);
3907
4265
  const userId = String(user._id);
3908
4266
  const resourceInfo = await getLicenseResourceInfo(user, licence);
3909
4267
  if (!resourceInfo) {