@timardex/cluemart-server-shared 1.0.287 → 1.0.291

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.
@@ -0,0 +1,17 @@
1
+ // src/types/index.ts
2
+ import express from "express";
3
+ import mongoose from "mongoose";
4
+ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
5
+ EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
6
+ EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
7
+ EnumPubSubEvents2["GET_NOTIFICATIONS_COUNT"] = "GET_NOTIFICATIONS_COUNT";
8
+ EnumPubSubEvents2["USER_TYPING"] = "USER_TYPING";
9
+ return EnumPubSubEvents2;
10
+ })(EnumPubSubEvents || {});
11
+
12
+ export {
13
+ express,
14
+ mongoose,
15
+ EnumPubSubEvents
16
+ };
17
+ //# sourceMappingURL=chunk-YXUJ4VQU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/index.ts"],"sourcesContent":["import { EnumUserRole } from \"@timardex/cluemart-shared\";\nimport { NotificationCount } from \"@timardex/cluemart-shared/types\";\nimport express from \"express\";\nimport mongoose from \"mongoose\";\n\nimport { SchemaChatType } from \"../mongoose/chat/Chat\";\nimport { SchemaNotificationType } from \"../mongoose/Notification\";\n\n// chnage to export type ObjectId = mongoose.Types.ObjectId;\n// chnage in server when setting decideGameType\nexport type ObjectId = mongoose.Types.ObjectId;\n\nexport enum EnumPubSubEvents {\n GET_CHAT_MESSAGE = \"GET_CHAT_MESSAGE\",\n GET_NOTIFICATIONS = \"GET_NOTIFICATIONS\",\n GET_NOTIFICATIONS_COUNT = \"GET_NOTIFICATIONS_COUNT\",\n USER_TYPING = \"USER_TYPING\",\n}\n\nexport interface AuthUser {\n email: string;\n role: EnumUserRole;\n userId: ObjectId;\n}\n\nexport interface SubscriptionPayload {\n getChatMessage?: SchemaChatType;\n userTyping?: SchemaChatType; // NOT USED\n getNotifications?: SchemaNotificationType[];\n // Used only for filtering; not part of the GraphQL schema output\n getNotificationsUserId?: ObjectId;\n getNotificationsCount?: NotificationCount & { userId: ObjectId };\n}\n\nexport interface GraphQLContext {\n appVersion: string | null;\n user: AuthUser | null;\n pubsub: {\n publish: (\n eventName: EnumPubSubEvents,\n payload: SubscriptionPayload,\n ) => void;\n subscribe: (eventName: EnumPubSubEvents) => AsyncIterable<any>;\n };\n request: express.Request;\n response: express.Response;\n}\n\nexport { mongoose, express };\n"],"mappings":";AAEA,OAAO,aAAa;AACpB,OAAO,cAAc;AASd,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,sBAAmB;AACnB,EAAAA,kBAAA,uBAAoB;AACpB,EAAAA,kBAAA,6BAA0B;AAC1B,EAAAA,kBAAA,iBAAc;AAJJ,SAAAA;AAAA,GAAA;","names":["EnumPubSubEvents"]}
package/dist/index.cjs CHANGED
@@ -78,9 +78,11 @@ __export(index_exports, {
78
78
  locationGeoSchema: () => locationGeoSchema,
79
79
  locationsSchema: () => locationsSchema,
80
80
  mapVendorLicenceToSubscriptionRewardType: () => mapVendorLicenceToSubscriptionRewardType,
81
- mongoose: () => import_mongoose37.default,
81
+ mongoose: () => import_mongoose30.default,
82
82
  normalizeAffiliatePromoCodes: () => normalizeAffiliatePromoCodes,
83
83
  normalizePromoCode: () => normalizePromoCode,
84
+ notifyUsers: () => notifyUsers,
85
+ publishNotificationEvents: () => publishNotificationEvents,
84
86
  refundPolicySchema: () => refundPolicySchema,
85
87
  relatedPostSchema: () => relatedPostSchema,
86
88
  relationDatesSchema: () => relationDatesSchema,
@@ -4754,29 +4756,6 @@ var tagOptions = availableTagTypes.map((tag) => ({
4754
4756
  label: tag.label,
4755
4757
  value: tag.label
4756
4758
  }));
4757
- var stallTypes = [
4758
- "1.8m table only",
4759
- "2x2m mini stall",
4760
- "3x3m tent site",
4761
- "Corner stall",
4762
- "Craft stall with power",
4763
- "Craft stall without power",
4764
- "Double stall (6x3m)",
4765
- "Food truck site",
4766
- "Food vendor with power",
4767
- "Food vendor without power",
4768
- "Inside hall stall",
4769
- "Non-profit/community stall",
4770
- "Outdoor open area",
4771
- "Shared table space",
4772
- "Wall-based vendor",
4773
- "Workshop/seating area"
4774
- ];
4775
- var stallTypeOptions = stallTypes.map((type) => ({
4776
- label: type,
4777
- price: 0,
4778
- stallCapacity: 0
4779
- }));
4780
4759
  var emailField = {
4781
4760
  helperText: "Enter email address",
4782
4761
  keyboardType: "email-address",
@@ -4801,6 +4780,51 @@ var companyContactFields = [
4801
4780
  placeholder: "Landline Phone Number"
4802
4781
  }
4803
4782
  ];
4783
+ var bankAccountDetailsFields = [
4784
+ {
4785
+ helperText: "Account holder name *",
4786
+ name: "accountHolderName",
4787
+ placeholder: "Account holder name"
4788
+ },
4789
+ {
4790
+ helperText: "Account number *",
4791
+ keyboardType: "number-pad",
4792
+ name: "accountNumber",
4793
+ placeholder: "Account number"
4794
+ }
4795
+ ];
4796
+ var eventInfoPaymentInfo = [
4797
+ ...bankAccountDetailsFields,
4798
+ {
4799
+ helperText: "Payment link, where applicants can pay *",
4800
+ keyboardType: "url",
4801
+ name: "link",
4802
+ placeholder: "Payment link"
4803
+ }
4804
+ ];
4805
+ var stallTypes = [
4806
+ "1.8m table only",
4807
+ "2x2m mini stall",
4808
+ "3x3m tent site",
4809
+ "Corner stall",
4810
+ "Craft stall with power",
4811
+ "Craft stall without power",
4812
+ "Double stall (6x3m)",
4813
+ "Food truck site",
4814
+ "Food vendor with power",
4815
+ "Food vendor without power",
4816
+ "Inside hall stall",
4817
+ "Non-profit/community stall",
4818
+ "Outdoor open area",
4819
+ "Shared table space",
4820
+ "Wall-based vendor",
4821
+ "Workshop/seating area"
4822
+ ];
4823
+ var stallTypeOptions = stallTypes.map((type) => ({
4824
+ label: type,
4825
+ price: 0,
4826
+ stallCapacity: 0
4827
+ }));
4804
4828
  var loginFields = [
4805
4829
  {
4806
4830
  ...emailField,
@@ -7572,8 +7596,10 @@ var AFFILIATE_FIELDS_FRAGMENT = gql`
7572
7596
  }
7573
7597
  createdAt
7574
7598
  deletedAt
7575
- lastRewardRedemptionAt
7576
- lastRewardRedemptionPoints
7599
+ redeemHistory {
7600
+ redeemedAt
7601
+ rewardValue
7602
+ }
7577
7603
  overallPoints
7578
7604
  owner {
7579
7605
  ...OwnerFields
@@ -8279,6 +8305,14 @@ var relatedPostSchema = new MongooseSchema6(
8279
8305
  { _id: false }
8280
8306
  // Prevents Mongoose from creating an additional _id field for subdocuments
8281
8307
  );
8308
+ var socialShareResourceSchema = new MongooseSchema6(
8309
+ {
8310
+ qrCode: { required: true, type: ResourceImageTypeSchema },
8311
+ socialImage: { required: true, type: ResourceImageTypeSchema }
8312
+ },
8313
+ { _id: false }
8314
+ // Prevents Mongoose from creating an additional _id field for subdocuments
8315
+ );
8282
8316
  var baseResourceFields = {
8283
8317
  active: { default: false, required: true, type: Boolean },
8284
8318
  adIds: {
@@ -8310,18 +8344,11 @@ var baseResourceFields = {
8310
8344
  region: { required: true, type: String },
8311
8345
  relatedPost: { required: false, type: relatedPostSchema },
8312
8346
  reviewCount: { required: false, type: Number },
8347
+ sharePublic: { required: false, type: socialShareResourceSchema },
8313
8348
  slug: { required: true, type: String },
8314
8349
  socialMedia: { required: false, type: [SocialMediaTypeSchema] },
8315
8350
  termsAgreement: { required: true, type: termsAgreementSchema }
8316
8351
  };
8317
- var socialShareResourceSchema = new MongooseSchema6(
8318
- {
8319
- qrCode: { required: true, type: ResourceImageTypeSchema },
8320
- socialImage: { required: true, type: ResourceImageTypeSchema }
8321
- },
8322
- { _id: false }
8323
- // Prevents Mongoose from creating an additional _id field for subdocuments
8324
- );
8325
8352
 
8326
8353
  // src/mongoose/GoogleImportedMarket.ts
8327
8354
  var import_mongoose7 = __toESM(require("mongoose"));
@@ -8798,7 +8825,6 @@ var schema9 = new MongooseSchema13(
8798
8825
  required: false,
8799
8826
  type: [resourceRelationsSchema]
8800
8827
  },
8801
- sharePublic: { required: false, type: socialShareResourceSchema },
8802
8828
  shareRelation: { required: false, type: socialShareResourceSchema },
8803
8829
  unregisteredVendorId: {
8804
8830
  ref: "UnregisteredVendor",
@@ -8951,7 +8977,6 @@ var schema12 = new MongooseSchema16(
8951
8977
  required: false,
8952
8978
  type: [resourceRelationsSchema]
8953
8979
  },
8954
- sharePublic: { required: false, type: socialShareResourceSchema },
8955
8980
  shareRelation: { required: false, type: socialShareResourceSchema },
8956
8981
  tags: { required: true, type: [String] }
8957
8982
  },
@@ -8983,8 +9008,7 @@ var schema13 = new MongooseSchema17(
8983
9008
  enum: Object.values(EnumPartnerType),
8984
9009
  required: true,
8985
9010
  type: String
8986
- },
8987
- sharePublic: { required: false, type: socialShareResourceSchema }
9011
+ }
8988
9012
  },
8989
9013
  { timestamps: true }
8990
9014
  );
@@ -9359,6 +9383,13 @@ var affiliateDetailsSchema = new MongooseSchema25(
9359
9383
  },
9360
9384
  { _id: false }
9361
9385
  );
9386
+ var redeemHistorySchema = new MongooseSchema25(
9387
+ {
9388
+ redeemedAt: { required: true, type: Date },
9389
+ rewardValue: { required: true, type: Number }
9390
+ },
9391
+ { _id: false }
9392
+ );
9362
9393
  var schema17 = new MongooseSchema25(
9363
9394
  {
9364
9395
  active: { default: false, required: true, type: Boolean },
@@ -9375,16 +9406,15 @@ var schema17 = new MongooseSchema25(
9375
9406
  type: [affiliateResourceSchema]
9376
9407
  },
9377
9408
  deletedAt: { default: null, required: false, type: Date },
9378
- lastRewardRedemptionAt: { default: null, required: false, type: Date },
9379
- lastRewardRedemptionPoints: {
9380
- default: null,
9381
- required: false,
9382
- type: Number
9383
- },
9384
9409
  overallPoints: { default: 0, required: true, type: Number },
9385
9410
  owner: {
9386
9411
  required: true,
9387
9412
  type: OwnerTypeSchema
9413
+ },
9414
+ redeemHistory: {
9415
+ default: [],
9416
+ required: false,
9417
+ type: [redeemHistorySchema]
9388
9418
  }
9389
9419
  },
9390
9420
  { timestamps: true }
@@ -9831,6 +9861,60 @@ var connectToDatabase = async ({
9831
9861
  }
9832
9862
  };
9833
9863
 
9864
+ // src/types/index.ts
9865
+ var import_express = __toESM(require("express"));
9866
+ var import_mongoose30 = __toESM(require("mongoose"));
9867
+ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
9868
+ EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
9869
+ EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
9870
+ EnumPubSubEvents2["GET_NOTIFICATIONS_COUNT"] = "GET_NOTIFICATIONS_COUNT";
9871
+ EnumPubSubEvents2["USER_TYPING"] = "USER_TYPING";
9872
+ return EnumPubSubEvents2;
9873
+ })(EnumPubSubEvents || {});
9874
+
9875
+ // src/service/notifyUsers.ts
9876
+ async function publishNotificationEvents(userId, pubsub) {
9877
+ try {
9878
+ const userNotifications = await NotificationModel.find({
9879
+ userId
9880
+ }).sort({ createdAt: -1 });
9881
+ const [total, unread] = await Promise.all([
9882
+ NotificationModel.countDocuments({ userId }),
9883
+ NotificationModel.countDocuments({ isRead: false, userId })
9884
+ ]);
9885
+ pubsub.publish("GET_NOTIFICATIONS" /* GET_NOTIFICATIONS */, {
9886
+ getNotifications: userNotifications,
9887
+ getNotificationsUserId: userId
9888
+ });
9889
+ pubsub.publish("GET_NOTIFICATIONS_COUNT" /* GET_NOTIFICATIONS_COUNT */, {
9890
+ getNotificationsCount: { total, unread, userId }
9891
+ });
9892
+ console.log(`Published notification events for user: ${String(userId)}`);
9893
+ } catch (error) {
9894
+ console.error(
9895
+ `Failed to publish notification events for user ${String(userId)}:`,
9896
+ error
9897
+ );
9898
+ }
9899
+ }
9900
+ async function notifyUsers({
9901
+ payload,
9902
+ pubsub
9903
+ }) {
9904
+ try {
9905
+ await sendPushNotifications(payload);
9906
+ const uniqueUserIds = await saveNotificationsInDb(payload);
9907
+ if (!pubsub) {
9908
+ return;
9909
+ }
9910
+ for (const userId of uniqueUserIds) {
9911
+ await publishNotificationEvents(userId, pubsub);
9912
+ }
9913
+ } catch (error) {
9914
+ console.error("Error in notifyUsers:", error);
9915
+ }
9916
+ }
9917
+
9834
9918
  // src/service/updateAdStatus.ts
9835
9919
  async function updateAdStatuses() {
9836
9920
  const now = /* @__PURE__ */ new Date();
@@ -9867,9 +9951,9 @@ async function updateAdStatuses() {
9867
9951
  }
9868
9952
 
9869
9953
  // src/service/associate.ts
9870
- var import_mongoose31 = __toESM(require("mongoose"));
9954
+ var import_mongoose32 = __toESM(require("mongoose"));
9871
9955
  function normalizeObjectId(id) {
9872
- return typeof id === "string" ? new import_mongoose31.default.Types.ObjectId(id) : id;
9956
+ return typeof id === "string" ? new import_mongoose32.default.Types.ObjectId(id) : id;
9873
9957
  }
9874
9958
  async function getAssociateEmailsForResource({
9875
9959
  normalizedResourceId,
@@ -10021,12 +10105,12 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
10021
10105
  }
10022
10106
 
10023
10107
  // src/service/objectIdToString.ts
10024
- var import_mongoose34 = __toESM(require("mongoose"));
10108
+ var import_mongoose35 = __toESM(require("mongoose"));
10025
10109
  function convertObjectIdsToStrings(obj) {
10026
10110
  if (obj === null || obj === void 0) {
10027
10111
  return obj;
10028
10112
  }
10029
- if (obj instanceof import_mongoose34.default.Types.ObjectId) {
10113
+ if (obj instanceof import_mongoose35.default.Types.ObjectId) {
10030
10114
  return obj.toString();
10031
10115
  }
10032
10116
  if (obj instanceof Date) {
@@ -10207,17 +10291,6 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
10207
10291
  };
10208
10292
  });
10209
10293
  }
10210
-
10211
- // src/types/index.ts
10212
- var import_express = __toESM(require("express"));
10213
- var import_mongoose37 = __toESM(require("mongoose"));
10214
- var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
10215
- EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
10216
- EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
10217
- EnumPubSubEvents2["GET_NOTIFICATIONS_COUNT"] = "GET_NOTIFICATIONS_COUNT";
10218
- EnumPubSubEvents2["USER_TYPING"] = "USER_TYPING";
10219
- return EnumPubSubEvents2;
10220
- })(EnumPubSubEvents || {});
10221
10294
  // Annotate the CommonJS export names for ESM import in node:
10222
10295
  0 && (module.exports = {
10223
10296
  ACTIVE_NOT_DELETED_FILTER,
@@ -10271,6 +10344,8 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
10271
10344
  mongoose,
10272
10345
  normalizeAffiliatePromoCodes,
10273
10346
  normalizePromoCode,
10347
+ notifyUsers,
10348
+ publishNotificationEvents,
10274
10349
  refundPolicySchema,
10275
10350
  relatedPostSchema,
10276
10351
  relationDatesSchema,