@timardex/cluemart-server-shared 1.0.263 → 1.0.264

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  APP_SETTINGS_ID: () => APP_SETTINGS_ID,
34
34
  AdModel: () => AdModel,
35
+ AffiliateModel: () => AffiliateModel,
35
36
  AppSettingModel: () => AppSettingModel,
36
37
  CategorySchema: () => CategorySchema,
37
38
  ChatModel: () => ChatModel,
@@ -69,7 +70,7 @@ __export(index_exports, {
69
70
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
70
71
  locationGeoSchema: () => locationGeoSchema,
71
72
  locationsSchema: () => locationsSchema,
72
- mongoose: () => import_mongoose33.default,
73
+ mongoose: () => import_mongoose34.default,
73
74
  refundPolicySchema: () => refundPolicySchema,
74
75
  relatedPostSchema: () => relatedPostSchema,
75
76
  relationDatesSchema: () => relationDatesSchema,
@@ -3569,6 +3570,7 @@ var gameScreenIdentifierList = [
3569
3570
  match: "/visitors"
3570
3571
  }
3571
3572
  ];
3573
+ var PROMO_CODE_PREFIX = "CM-";
3572
3574
  var EnumAdShowOn = /* @__PURE__ */ ((EnumAdShowOn2) => {
3573
3575
  EnumAdShowOn2["EVENTS_PAGE"] = "Events_page";
3574
3576
  EnumAdShowOn2["FRONT_PAGE"] = "Front_page";
@@ -3627,6 +3629,12 @@ var EnumGameType = /* @__PURE__ */ ((EnumGameType2) => {
3627
3629
  EnumGameType2["ODD_ONE_OUT"] = "oddOneOut";
3628
3630
  return EnumGameType2;
3629
3631
  })(EnumGameType || {});
3632
+ var EnumAffiliateRewardType = /* @__PURE__ */ ((EnumAffiliateRewardType2) => {
3633
+ EnumAffiliateRewardType2["NEW_EVENT_REGISTRATION"] = "NEW_EVENT_REGISTRATION";
3634
+ EnumAffiliateRewardType2["NEW_VENDOR_REGISTRATION"] = "NEW_VENDOR_REGISTRATION";
3635
+ EnumAffiliateRewardType2["NEW_PARTNER_REGISTRATION"] = "NEW_PARTNER_REGISTRATION";
3636
+ return EnumAffiliateRewardType2;
3637
+ })(EnumAffiliateRewardType || {});
3630
3638
  var mapArrayToOptions = (items) => items.map((item) => ({
3631
3639
  label: item,
3632
3640
  value: item
@@ -3644,6 +3652,8 @@ var paymentMethodOptions = mapArrayToOptions(
3644
3652
  Object.values(EnumPaymentMethod)
3645
3653
  );
3646
3654
  var CLUEMART_MAIN_DOMAIN_URL = "https://cluemart.co.nz";
3655
+ var CM_SCHOOL_PROMO_CODE = `${PROMO_CODE_PREFIX}SCHOOL`;
3656
+ var CM_AFFILIATE_PROMO_CODE = `${PROMO_CODE_PREFIX}AFFILIATE`;
3647
3657
  var dateFormat = "DD-MM-YYYY";
3648
3658
  var timeFormat = "HH:mm";
3649
3659
  import_dayjs.default.extend(import_customParseFormat.default);
@@ -5039,12 +5049,6 @@ var REDEEMED_REWARD_FIELDS_FRAGMENT = gql`
5039
5049
  redeemedAt
5040
5050
  }
5041
5051
  `;
5042
- var AFFILIATE_FIELDS_FRAGMENT = gql`
5043
- fragment AffiliateFields on AffiliateType {
5044
- affiliateCode
5045
- pointsAvailable
5046
- }
5047
- `;
5048
5052
  var USER_FIELDS_FRAGMENT = gql`
5049
5053
  fragment UserFields on UserType {
5050
5054
  _id
@@ -5052,9 +5056,7 @@ var USER_FIELDS_FRAGMENT = gql`
5052
5056
  associates {
5053
5057
  ...AssociatesFields
5054
5058
  }
5055
- affiliate {
5056
- ...AffiliateFields
5057
- }
5059
+ affiliate
5058
5060
  avatar {
5059
5061
  ...ResourceImageFields
5060
5062
  }
@@ -5098,7 +5100,6 @@ var USER_FIELDS_FRAGMENT = gql`
5098
5100
  ${LICENCE_FIELDS_FRAGMENT}
5099
5101
  ${LOCATION_FIELDS_FRAGMENT}
5100
5102
  ${REDEEMED_REWARD_FIELDS_FRAGMENT}
5101
- ${AFFILIATE_FIELDS_FRAGMENT}
5102
5103
  `;
5103
5104
  var STALL_TYPE_FIELDS_FRAGMENT = gql`
5104
5105
  fragment StallTypeFields on StallTypeType {
@@ -7444,6 +7445,62 @@ var REQUEST_MARKETING_MATERIAL_MUTATION = gql`
7444
7445
  }
7445
7446
  }
7446
7447
  `;
7448
+ var AFFILIATE_REWARD_FIELDS_FRAGMENT = gql`
7449
+ fragment AffiliateRewardFields on AffiliateRewardType {
7450
+ createdAt
7451
+ deletedAt
7452
+ redeemedAt
7453
+ rewardDescription
7454
+ rewardType
7455
+ rewardValue
7456
+ updatedAt
7457
+ }
7458
+ `;
7459
+ var AFFILIATE_RESOURCE_FIELDS_FRAGMENT = gql`
7460
+ fragment AffiliateResourceFields on AffiliateResourceType {
7461
+ resourceActive
7462
+ resourceId
7463
+ resourceType
7464
+ rewards {
7465
+ ...AffiliateRewardFields
7466
+ }
7467
+ }
7468
+ ${AFFILIATE_REWARD_FIELDS_FRAGMENT}
7469
+ `;
7470
+ var AFFILIATE_FIELDS_FRAGMENT = gql`
7471
+ fragment AffiliateFields on AffiliateType {
7472
+ _id
7473
+ affiliateCode
7474
+ affiliateResources {
7475
+ ...AffiliateResourceFields
7476
+ }
7477
+ createdAt
7478
+ deletedAt
7479
+ overallPoints
7480
+ owner {
7481
+ ...OwnerFields
7482
+ }
7483
+ updatedAt
7484
+ }
7485
+ ${AFFILIATE_RESOURCE_FIELDS_FRAGMENT}
7486
+ ${OWNER_FIELDS_FRAGMENT}
7487
+ `;
7488
+ var GET_AFFILIATE = gql`
7489
+ query getAffiliate($_id: ID!) {
7490
+ affiliate(_id: $_id) {
7491
+ ...AffiliateFields
7492
+ }
7493
+ }
7494
+ ${AFFILIATE_FIELDS_FRAGMENT}
7495
+ `;
7496
+ var GET_AFFILIATES = gql`
7497
+ query getAffiliates {
7498
+ affiliates {
7499
+ ...AffiliateFields
7500
+ }
7501
+ }
7502
+ ${AFFILIATE_FIELDS_FRAGMENT}
7503
+ `;
7447
7504
  var PKG = "@timardex/cluemart-shared";
7448
7505
  var IMAGE_EXTENSION = ".webp";
7449
7506
  var posterIds = [
@@ -8458,19 +8515,13 @@ var redeemedRewardSchema = new MongooseSchema11(
8458
8515
  },
8459
8516
  { _id: false }
8460
8517
  );
8461
- var affiliateSchema = new MongooseSchema11(
8462
- {
8463
- affiliateCode: { required: true, type: String },
8464
- pointsAvailable: { required: true, type: Number }
8465
- },
8466
- { _id: false }
8467
- );
8468
8518
  var schema7 = new MongooseSchema11(
8469
8519
  {
8470
8520
  active: { default: false, required: true, type: Boolean },
8471
8521
  affiliate: {
8522
+ ref: "Affiliate",
8472
8523
  required: false,
8473
- type: affiliateSchema
8524
+ type: import_mongoose11.default.Schema.Types.ObjectId
8474
8525
  },
8475
8526
  associates: {
8476
8527
  required: false,
@@ -8570,13 +8621,6 @@ var schema7 = new MongooseSchema11(
8570
8621
  },
8571
8622
  { strict: false, timestamps: true }
8572
8623
  );
8573
- schema7.index(
8574
- { "affiliate.affiliateCode": 1 },
8575
- {
8576
- partialFilterExpression: { active: true, deletedAt: null },
8577
- unique: true
8578
- }
8579
- );
8580
8624
  schema7.index({ "associates.email": 1 });
8581
8625
  schema7.index({ "licences.expiryDate": 1 });
8582
8626
  schema7.index({ "licences.licenceType": 1 });
@@ -9067,9 +9111,9 @@ var gameDataSchemas = {
9067
9111
  [EnumGameType.ODD_ONE_OUT]: schemaPuzzleGameData
9068
9112
  };
9069
9113
  var gameDataDefinition = Object.fromEntries(
9070
- Object.entries(gameDataSchemas).map(([key, schema17]) => [
9114
+ Object.entries(gameDataSchemas).map(([key, schema18]) => [
9071
9115
  key,
9072
- { default: null, required: false, type: schema17 }
9116
+ { default: null, required: false, type: schema18 }
9073
9117
  ])
9074
9118
  );
9075
9119
  var gameHistorySchema = new MongooseSchema23(
@@ -9168,8 +9212,73 @@ schema16.index(
9168
9212
  );
9169
9213
  var SchoolModel = import_mongoose24.default.models.School || import_mongoose24.default.model("School", schema16);
9170
9214
 
9171
- // src/service/database.ts
9215
+ // src/mongoose/Affiliate.ts
9172
9216
  var import_mongoose25 = __toESM(require("mongoose"));
9217
+ var MongooseSchema25 = import_mongoose25.default.Schema;
9218
+ var affiliateRewardSchema = new MongooseSchema25(
9219
+ {
9220
+ createdAt: { required: true, type: Date },
9221
+ deletedAt: { default: null, required: false, type: Date },
9222
+ redeemedAt: { default: null, required: false, type: Date },
9223
+ rewardDescription: { required: true, type: String },
9224
+ rewardType: {
9225
+ enum: Object.values(EnumAffiliateRewardType),
9226
+ required: true,
9227
+ type: String
9228
+ },
9229
+ rewardValue: { required: true, type: Number },
9230
+ updatedAt: { default: null, required: false, type: Date }
9231
+ },
9232
+ { _id: false }
9233
+ );
9234
+ var affiliateResourceSchema = new MongooseSchema25(
9235
+ {
9236
+ resourceActive: { default: true, required: true, type: Boolean },
9237
+ resourceId: {
9238
+ required: true,
9239
+ type: import_mongoose25.default.Schema.Types.ObjectId
9240
+ },
9241
+ resourceType: {
9242
+ enum: Object.values(EnumResourceType),
9243
+ required: true,
9244
+ type: String
9245
+ },
9246
+ rewards: {
9247
+ default: [],
9248
+ required: false,
9249
+ type: [affiliateRewardSchema]
9250
+ }
9251
+ },
9252
+ { _id: false }
9253
+ );
9254
+ var schema17 = new MongooseSchema25(
9255
+ {
9256
+ affiliateCode: { required: true, type: String },
9257
+ affiliateResources: {
9258
+ default: [],
9259
+ required: false,
9260
+ type: [affiliateResourceSchema]
9261
+ },
9262
+ deletedAt: { default: null, required: false, type: Date },
9263
+ overallPoints: { default: 0, required: true, type: Number },
9264
+ owner: {
9265
+ required: true,
9266
+ type: OwnerTypeSchema
9267
+ }
9268
+ },
9269
+ { timestamps: true }
9270
+ );
9271
+ schema17.index(
9272
+ { affiliateCode: 1 },
9273
+ {
9274
+ partialFilterExpression: { deletedAt: null },
9275
+ unique: true
9276
+ }
9277
+ );
9278
+ var AffiliateModel = import_mongoose25.default.models.Affiliate || import_mongoose25.default.model("Affiliate", schema17);
9279
+
9280
+ // src/service/database.ts
9281
+ var import_mongoose26 = __toESM(require("mongoose"));
9173
9282
  var connectToDatabase = async ({
9174
9283
  appName,
9175
9284
  dbName,
@@ -9182,7 +9291,7 @@ var connectToDatabase = async ({
9182
9291
  // Fallback to MongoDB Atlas connection string
9183
9292
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
9184
9293
  );
9185
- await import_mongoose25.default.connect(mongoUri);
9294
+ await import_mongoose26.default.connect(mongoUri);
9186
9295
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
9187
9296
  console.log(
9188
9297
  `${connectionType} connected from server/src/service/database.ts`
@@ -9362,9 +9471,9 @@ async function updateAdStatuses() {
9362
9471
  }
9363
9472
 
9364
9473
  // src/service/associate.ts
9365
- var import_mongoose27 = __toESM(require("mongoose"));
9474
+ var import_mongoose28 = __toESM(require("mongoose"));
9366
9475
  function normalizeObjectId(id) {
9367
- return typeof id === "string" ? new import_mongoose27.default.Types.ObjectId(id) : id;
9476
+ return typeof id === "string" ? new import_mongoose28.default.Types.ObjectId(id) : id;
9368
9477
  }
9369
9478
  async function getAssociateEmailsForResource({
9370
9479
  normalizedResourceId,
@@ -9516,12 +9625,12 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
9516
9625
  }
9517
9626
 
9518
9627
  // src/service/objectIdToString.ts
9519
- var import_mongoose30 = __toESM(require("mongoose"));
9628
+ var import_mongoose31 = __toESM(require("mongoose"));
9520
9629
  function convertObjectIdsToStrings(obj) {
9521
9630
  if (obj === null || obj === void 0) {
9522
9631
  return obj;
9523
9632
  }
9524
- if (obj instanceof import_mongoose30.default.Types.ObjectId) {
9633
+ if (obj instanceof import_mongoose31.default.Types.ObjectId) {
9525
9634
  return obj.toString();
9526
9635
  }
9527
9636
  if (obj instanceof Date) {
@@ -9705,7 +9814,7 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
9705
9814
 
9706
9815
  // src/types/index.ts
9707
9816
  var import_express = __toESM(require("express"));
9708
- var import_mongoose33 = __toESM(require("mongoose"));
9817
+ var import_mongoose34 = __toESM(require("mongoose"));
9709
9818
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9710
9819
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
9711
9820
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -9717,6 +9826,7 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9717
9826
  0 && (module.exports = {
9718
9827
  APP_SETTINGS_ID,
9719
9828
  AdModel,
9829
+ AffiliateModel,
9720
9830
  AppSettingModel,
9721
9831
  CategorySchema,
9722
9832
  ChatModel,