@timardex/cluemart-server-shared 1.0.297 → 1.0.300

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
@@ -63,7 +63,6 @@ __export(index_exports, {
63
63
  VendorModel: () => VendorModel,
64
64
  VerificationTokenModel: () => VerificationTokenModel,
65
65
  activeAffiliateCodeExists: () => activeAffiliateCodeExists,
66
- associatesSchema: () => associatesSchema,
67
66
  awardAffiliateVendorSubscriptionRewards: () => awardAffiliateVendorSubscriptionRewards,
68
67
  baseResourceFields: () => baseResourceFields,
69
68
  connectToDatabase: () => connectToDatabase,
@@ -3380,9 +3379,6 @@ var EnumRelationResource = /* @__PURE__ */ ((EnumRelationResource22) => {
3380
3379
  return EnumRelationResource22;
3381
3380
  })(EnumRelationResource || {});
3382
3381
  var EnumNotificationResourceType = /* @__PURE__ */ ((EnumNotificationResourceType22) => {
3383
- EnumNotificationResourceType22["ADDED_AS_ASSOCIATE_EVENT"] = "added_as_associate_event";
3384
- EnumNotificationResourceType22["ADDED_AS_ASSOCIATE_PARTNER"] = "added_as_associate_partner";
3385
- EnumNotificationResourceType22["ADDED_AS_ASSOCIATE_VENDOR"] = "added_as_associate_vendor";
3386
3382
  EnumNotificationResourceType22["APPROVED_AFFILIATE"] = "approved_affiliate";
3387
3383
  EnumNotificationResourceType22["AFFILIATE_REWARD_RECEIVED"] = "affiliate_reward_received";
3388
3384
  EnumNotificationResourceType22["APPROVED_EVENT"] = "approved_event";
@@ -3454,13 +3450,13 @@ var EnumUserLicence = /* @__PURE__ */ ((EnumUserLicence22) => {
3454
3450
  })(EnumUserLicence || {});
3455
3451
  var EnumUserRole = /* @__PURE__ */ ((EnumUserRole22) => {
3456
3452
  EnumUserRole22["ADMIN"] = "admin";
3457
- EnumUserRole22["SUPER_ADMIN"] = "super_admin";
3458
- EnumUserRole22["CUSTOMER"] = "customer";
3459
- EnumUserRole22["MARKETING"] = "marketing";
3460
- EnumUserRole22["MODERATOR"] = "moderator";
3461
- EnumUserRole22["SUPPORT"] = "support";
3462
3453
  EnumUserRole22["AFFILIATE"] = "affiliate";
3454
+ EnumUserRole22["CUSTOMER"] = "customer";
3455
+ EnumUserRole22["EVENT"] = "event";
3456
+ EnumUserRole22["PARTNER"] = "partner";
3463
3457
  EnumUserRole22["SCHOOL"] = "school";
3458
+ EnumUserRole22["SUPER_ADMIN"] = "super_admin";
3459
+ EnumUserRole22["VENDOR"] = "vendor";
3464
3460
  return EnumUserRole22;
3465
3461
  })(EnumUserRole || {});
3466
3462
  var EnumEventDateStatus = /* @__PURE__ */ ((EnumEventDateStatus22) => {
@@ -5046,17 +5042,6 @@ var LICENCE_FIELDS_FRAGMENT = gql`
5046
5042
  prevLicenceType
5047
5043
  }
5048
5044
  `;
5049
- var ASSOCIATES_FIELDS_FRAGMENT = gql`
5050
- fragment AssociatesFields on AssociateType {
5051
- email
5052
- resourceId
5053
- resourceType
5054
- licence {
5055
- ...LicenceFields
5056
- }
5057
- }
5058
- ${LICENCE_FIELDS_FRAGMENT}
5059
- `;
5060
5045
  var TERMS_AGREEMENT_FIELDS_FRAGMENT = gql`
5061
5046
  fragment TermsAgreementFields on TermsAgreementType {
5062
5047
  appBuildNumber
@@ -5147,9 +5132,6 @@ var USER_FIELDS_FRAGMENT = gql`
5147
5132
  fragment UserFields on UserType {
5148
5133
  _id
5149
5134
  active
5150
- associates {
5151
- ...AssociatesFields
5152
- }
5153
5135
  affiliate
5154
5136
  avatar {
5155
5137
  ...ResourceImageFields
@@ -5172,8 +5154,9 @@ var USER_FIELDS_FRAGMENT = gql`
5172
5154
  overallPoints
5173
5155
  platform
5174
5156
  preferredRegion
5157
+ permissions
5175
5158
  promoCodes
5176
- role
5159
+ roles
5177
5160
  redeemedRewards {
5178
5161
  ...RedeemedRewardFields
5179
5162
  }
@@ -5188,7 +5171,6 @@ var USER_FIELDS_FRAGMENT = gql`
5188
5171
  updatedAt
5189
5172
  }
5190
5173
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5191
- ${ASSOCIATES_FIELDS_FRAGMENT}
5192
5174
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
5193
5175
  ${USER_ACTIVITY_FIELDS_FRAGMENT}
5194
5176
  ${LICENCE_FIELDS_FRAGMENT}
@@ -5334,9 +5316,6 @@ var EVENT = gql`
5334
5316
  fragment EventFields on EventType {
5335
5317
  _id
5336
5318
  active
5337
- associates {
5338
- ...AssociatesFields
5339
- }
5340
5319
  adIds
5341
5320
  approvedAt
5342
5321
  cover {
@@ -5409,7 +5388,6 @@ var EVENT = gql`
5409
5388
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5410
5389
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
5411
5390
  ${POSTER_USAGE_FIELDS_FRAGMENT}
5412
- ${ASSOCIATES_FIELDS_FRAGMENT}
5413
5391
  ${CONTACT_DETAILS_FIELDS_FRAGMENT}
5414
5392
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
5415
5393
  ${RELATION_DATES_FRAGMENT}
@@ -5522,9 +5500,6 @@ var VENDOR = gql`
5522
5500
  fragment VendorFields on VendorType {
5523
5501
  _id
5524
5502
  active
5525
- associates {
5526
- ...AssociatesFields
5527
- }
5528
5503
  adIds
5529
5504
  approvedAt
5530
5505
  availability {
@@ -5615,7 +5590,6 @@ var VENDOR = gql`
5615
5590
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5616
5591
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
5617
5592
  ${POSTER_USAGE_FIELDS_FRAGMENT}
5618
- ${ASSOCIATES_FIELDS_FRAGMENT}
5619
5593
  ${VENDOR_PRODUCT_LIST_FIELDS_FRAGMENT}
5620
5594
  ${CONTACT_DETAILS_FIELDS_FRAGMENT}
5621
5595
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
@@ -5768,9 +5742,6 @@ var PARTNER = gql`
5768
5742
  fragment PartnerFields on PartnerType {
5769
5743
  _id
5770
5744
  active
5771
- associates {
5772
- ...AssociatesFields
5773
- }
5774
5745
  adIds
5775
5746
  approvedAt
5776
5747
  cover {
@@ -5821,7 +5792,6 @@ var PARTNER = gql`
5821
5792
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
5822
5793
  ${LOCATION_FIELDS_FRAGMENT}
5823
5794
  ${OWNER_FIELDS_FRAGMENT}
5824
- ${ASSOCIATES_FIELDS_FRAGMENT}
5825
5795
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
5826
5796
  ${POSTER_USAGE_FIELDS_FRAGMENT}
5827
5797
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
@@ -6268,7 +6238,6 @@ var CHAT_MESSAGE_FIELDS_FRAGMENT = gql`
6268
6238
  var CHAT_PARTICIPANT = gql`
6269
6239
  fragment ChatParticipantFields on ChatParticipantType {
6270
6240
  active
6271
- isAssociate
6272
6241
  userAvatar
6273
6242
  userEmail
6274
6243
  userId
@@ -7746,7 +7715,6 @@ var MessageSchema = new MongooseSchema2(
7746
7715
  var ParticipantSchema = new MongooseSchema2(
7747
7716
  {
7748
7717
  active: { default: true, required: true, type: Boolean },
7749
- isAssociate: { default: null, required: false, type: Boolean },
7750
7718
  userAvatar: { required: false, type: String },
7751
7719
  userEmail: { required: true, type: String },
7752
7720
  userId: {
@@ -8071,26 +8039,6 @@ var userLicenseSchema = new MongooseSchema6(
8071
8039
  },
8072
8040
  { _id: false, timestamps: false }
8073
8041
  );
8074
- var associatesSchema = new MongooseSchema6(
8075
- {
8076
- email: { required: true, type: String },
8077
- licence: {
8078
- required: true,
8079
- type: userLicenseSchema
8080
- },
8081
- resourceId: {
8082
- required: true,
8083
- type: String
8084
- },
8085
- resourceType: {
8086
- enum: Object.values(EnumResourceType),
8087
- required: true,
8088
- type: String
8089
- }
8090
- },
8091
- { _id: false }
8092
- // Prevents Mongoose from creating an additional _id field for subdocuments
8093
- );
8094
8042
  var ContactDetailsSchema = new MongooseSchema6(
8095
8043
  {
8096
8044
  email: { required: false, type: String },
@@ -8206,10 +8154,6 @@ var baseResourceFields = {
8206
8154
  type: [import_mongoose6.default.Schema.Types.ObjectId]
8207
8155
  },
8208
8156
  approvedAt: { default: null, required: false, type: Date },
8209
- associates: {
8210
- required: false,
8211
- type: [associatesSchema]
8212
- },
8213
8157
  contactDetails: { required: false, type: ContactDetailsSchema },
8214
8158
  cover: {
8215
8159
  required: true,
@@ -8353,7 +8297,7 @@ schema4.index({ isRead: 1, userId: 1 });
8353
8297
  schema4.index({ createdAt: -1, userId: 1 });
8354
8298
  var NotificationModel = import_mongoose8.default.models.Notification || import_mongoose8.default.model("Notification", schema4);
8355
8299
 
8356
- // node_modules/@timardex/cluemart-shared/dist/chunk-D33VEY7Q.mjs
8300
+ // node_modules/@timardex/cluemart-shared/dist/chunk-X3OLM35T.mjs
8357
8301
  var EnumOSPlatform2 = /* @__PURE__ */ ((EnumOSPlatform22) => {
8358
8302
  EnumOSPlatform22["ANDROID"] = "android";
8359
8303
  EnumOSPlatform22["IOS"] = "ios";
@@ -8514,10 +8458,6 @@ var schema7 = new MongooseSchema11(
8514
8458
  required: false,
8515
8459
  type: import_mongoose11.default.Schema.Types.ObjectId
8516
8460
  },
8517
- associates: {
8518
- required: false,
8519
- type: [associatesSchema]
8520
- },
8521
8461
  avatar: {
8522
8462
  required: false,
8523
8463
  type: ResourceImageTypeSchema
@@ -8578,11 +8518,11 @@ var schema7 = new MongooseSchema11(
8578
8518
  required: false,
8579
8519
  type: String
8580
8520
  },
8581
- role: {
8582
- default: EnumUserRole.CUSTOMER,
8521
+ roles: {
8522
+ default: [EnumUserRole.CUSTOMER],
8583
8523
  enum: Object.values(EnumUserRole),
8584
8524
  required: true,
8585
- type: String
8525
+ type: [String]
8586
8526
  },
8587
8527
  school: {
8588
8528
  ref: "School",
@@ -8617,7 +8557,6 @@ var schema7 = new MongooseSchema11(
8617
8557
  },
8618
8558
  { strict: false, timestamps: true }
8619
8559
  );
8620
- schema7.index({ "associates.email": 1 });
8621
8560
  schema7.index({ "licences.expiryDate": 1 });
8622
8561
  schema7.index({ "licences.licenceType": 1 });
8623
8562
  var UserModel = import_mongoose11.default.models.User || import_mongoose11.default.model("User", schema7);
@@ -8735,7 +8674,6 @@ schema9.index({ name: 1 });
8735
8674
  schema9.index({ description: 1 });
8736
8675
  schema9.index({ region: 1 });
8737
8676
  schema9.index({ "categories.name": 1 });
8738
- schema9.index({ "associates.email": 1 });
8739
8677
  schema9.index({ slug: 1 });
8740
8678
  var VendorModel = import_mongoose13.default.models.Vendor || import_mongoose13.default.model("Vendor", schema9);
8741
8679
 
@@ -8874,7 +8812,6 @@ schema12.index({ description: 1 });
8874
8812
  schema12.index({ region: 1 });
8875
8813
  schema12.index({ "location.geo": "2dsphere" });
8876
8814
  schema12.index({ tags: 1 });
8877
- schema12.index({ "associates.email": 1 });
8878
8815
  schema12.index({ deletedAt: 1 });
8879
8816
  schema12.index({ "dateTime.dateStatus": 1 });
8880
8817
  schema12.index({ slug: 1 });
@@ -8903,7 +8840,6 @@ schema13.index({ name: 1 });
8903
8840
  schema13.index({ description: 1 });
8904
8841
  schema13.index({ region: 1 });
8905
8842
  schema13.index({ "location.geo": "2dsphere" });
8906
- schema13.index({ "associates.email": 1 });
8907
8843
  schema13.index({ slug: 1 });
8908
8844
  var PartnerModel = import_mongoose17.default.models.Partner || import_mongoose17.default.model("Partner", schema13);
8909
8845
 
@@ -9852,112 +9788,6 @@ async function updateAdStatuses() {
9852
9788
  );
9853
9789
  }
9854
9790
 
9855
- // src/service/associate.ts
9856
- var import_mongoose32 = __toESM(require("mongoose"));
9857
- function normalizeObjectId(id) {
9858
- return typeof id === "string" ? new import_mongoose32.default.Types.ObjectId(id) : id;
9859
- }
9860
- async function getAssociateEmailsForResource({
9861
- normalizedResourceId,
9862
- resourceType
9863
- }) {
9864
- const usersWithAssociates = await UserModel.find(
9865
- {
9866
- associates: {
9867
- $elemMatch: {
9868
- resourceId: normalizedResourceId,
9869
- resourceType
9870
- }
9871
- }
9872
- },
9873
- {
9874
- associates: 1
9875
- }
9876
- ).lean();
9877
- return [
9878
- ...new Set(
9879
- usersWithAssociates.flatMap(
9880
- (user) => (user.associates ?? []).filter(
9881
- (associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
9882
- ).map((associate) => associate.email)
9883
- )
9884
- )
9885
- ];
9886
- }
9887
- async function pullAssociatesFromUsers({
9888
- normalizedResourceId,
9889
- resourceType
9890
- }) {
9891
- await UserModel.updateMany(
9892
- {
9893
- associates: {
9894
- $elemMatch: {
9895
- resourceId: normalizedResourceId,
9896
- resourceType
9897
- }
9898
- }
9899
- },
9900
- {
9901
- $pull: {
9902
- associates: {
9903
- resourceId: normalizedResourceId,
9904
- resourceType
9905
- }
9906
- }
9907
- }
9908
- );
9909
- }
9910
- async function pullAssociateParticipantsFromChats(resourceOwnerId, associateEmails) {
9911
- await ChatModel.updateMany(
9912
- {
9913
- active: true,
9914
- chatType: EnumChatType.RELATION,
9915
- deletedAt: null,
9916
- participants: {
9917
- $elemMatch: {
9918
- userId: resourceOwnerId
9919
- }
9920
- }
9921
- },
9922
- {
9923
- $pull: {
9924
- participants: {
9925
- isAssociate: true,
9926
- userEmail: {
9927
- $in: associateEmails
9928
- }
9929
- }
9930
- }
9931
- }
9932
- );
9933
- }
9934
- async function removeAssociateFromResource({
9935
- resourceId,
9936
- resourceOwnerId,
9937
- resourceType
9938
- }) {
9939
- try {
9940
- const scope = {
9941
- normalizedResourceId: resourceId.toString(),
9942
- resourceType
9943
- };
9944
- const associateEmails = await getAssociateEmailsForResource(scope);
9945
- if (associateEmails.length === 0) {
9946
- return;
9947
- }
9948
- await pullAssociatesFromUsers(scope);
9949
- await pullAssociateParticipantsFromChats(
9950
- normalizeObjectId(resourceOwnerId),
9951
- associateEmails
9952
- );
9953
- } catch (error) {
9954
- console.error(
9955
- `[removeAssociateFromResource] Failed for resourceId=${resourceId}, resourceType=${resourceType}`,
9956
- error
9957
- );
9958
- }
9959
- }
9960
-
9961
9791
  // src/service/vendor.ts
9962
9792
  async function updateVendorBasedOnUserLicense(userId, licenceType) {
9963
9793
  try {
@@ -9974,7 +9804,6 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
9974
9804
  const updateData = {};
9975
9805
  const isStandardVendor = licenceType === EnumUserLicence.STANDARD_VENDOR;
9976
9806
  if (isStandardVendor) {
9977
- updateData.associates = [];
9978
9807
  updateData.availability = {
9979
9808
  corporate: false,
9980
9809
  private: false,
@@ -9994,25 +9823,18 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
9994
9823
  active: isStandardVendor ? index < 6 : true
9995
9824
  }));
9996
9825
  await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
9997
- if (isStandardVendor) {
9998
- await removeAssociateFromResource({
9999
- resourceId: vendor._id,
10000
- resourceOwnerId: vendor.owner.userId,
10001
- resourceType: EnumResourceType.VENDOR
10002
- });
10003
- }
10004
9826
  } catch (error) {
10005
9827
  console.error("[updateVendorBasedOnUserLicense] Failed:", error);
10006
9828
  }
10007
9829
  }
10008
9830
 
10009
9831
  // src/service/objectIdToString.ts
10010
- var import_mongoose35 = __toESM(require("mongoose"));
9832
+ var import_mongoose33 = __toESM(require("mongoose"));
10011
9833
  function convertObjectIdsToStrings(obj) {
10012
9834
  if (obj === null || obj === void 0) {
10013
9835
  return obj;
10014
9836
  }
10015
- if (obj instanceof import_mongoose35.default.Types.ObjectId) {
9837
+ if (obj instanceof import_mongoose33.default.Types.ObjectId) {
10016
9838
  return obj.toString();
10017
9839
  }
10018
9840
  if (obj instanceof Date) {
@@ -10228,7 +10050,6 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
10228
10050
  VendorModel,
10229
10051
  VerificationTokenModel,
10230
10052
  activeAffiliateCodeExists,
10231
- associatesSchema,
10232
10053
  awardAffiliateVendorSubscriptionRewards,
10233
10054
  baseResourceFields,
10234
10055
  connectToDatabase,