@timardex/cluemart-server-shared 1.0.289 → 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,
@@ -8303,6 +8305,14 @@ var relatedPostSchema = new MongooseSchema6(
8303
8305
  { _id: false }
8304
8306
  // Prevents Mongoose from creating an additional _id field for subdocuments
8305
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
+ );
8306
8316
  var baseResourceFields = {
8307
8317
  active: { default: false, required: true, type: Boolean },
8308
8318
  adIds: {
@@ -8334,18 +8344,11 @@ var baseResourceFields = {
8334
8344
  region: { required: true, type: String },
8335
8345
  relatedPost: { required: false, type: relatedPostSchema },
8336
8346
  reviewCount: { required: false, type: Number },
8347
+ sharePublic: { required: false, type: socialShareResourceSchema },
8337
8348
  slug: { required: true, type: String },
8338
8349
  socialMedia: { required: false, type: [SocialMediaTypeSchema] },
8339
8350
  termsAgreement: { required: true, type: termsAgreementSchema }
8340
8351
  };
8341
- var socialShareResourceSchema = new MongooseSchema6(
8342
- {
8343
- qrCode: { required: true, type: ResourceImageTypeSchema },
8344
- socialImage: { required: true, type: ResourceImageTypeSchema }
8345
- },
8346
- { _id: false }
8347
- // Prevents Mongoose from creating an additional _id field for subdocuments
8348
- );
8349
8352
 
8350
8353
  // src/mongoose/GoogleImportedMarket.ts
8351
8354
  var import_mongoose7 = __toESM(require("mongoose"));
@@ -8822,7 +8825,6 @@ var schema9 = new MongooseSchema13(
8822
8825
  required: false,
8823
8826
  type: [resourceRelationsSchema]
8824
8827
  },
8825
- sharePublic: { required: false, type: socialShareResourceSchema },
8826
8828
  shareRelation: { required: false, type: socialShareResourceSchema },
8827
8829
  unregisteredVendorId: {
8828
8830
  ref: "UnregisteredVendor",
@@ -8975,7 +8977,6 @@ var schema12 = new MongooseSchema16(
8975
8977
  required: false,
8976
8978
  type: [resourceRelationsSchema]
8977
8979
  },
8978
- sharePublic: { required: false, type: socialShareResourceSchema },
8979
8980
  shareRelation: { required: false, type: socialShareResourceSchema },
8980
8981
  tags: { required: true, type: [String] }
8981
8982
  },
@@ -9007,8 +9008,7 @@ var schema13 = new MongooseSchema17(
9007
9008
  enum: Object.values(EnumPartnerType),
9008
9009
  required: true,
9009
9010
  type: String
9010
- },
9011
- sharePublic: { required: false, type: socialShareResourceSchema }
9011
+ }
9012
9012
  },
9013
9013
  { timestamps: true }
9014
9014
  );
@@ -9861,6 +9861,60 @@ var connectToDatabase = async ({
9861
9861
  }
9862
9862
  };
9863
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
+
9864
9918
  // src/service/updateAdStatus.ts
9865
9919
  async function updateAdStatuses() {
9866
9920
  const now = /* @__PURE__ */ new Date();
@@ -9897,9 +9951,9 @@ async function updateAdStatuses() {
9897
9951
  }
9898
9952
 
9899
9953
  // src/service/associate.ts
9900
- var import_mongoose31 = __toESM(require("mongoose"));
9954
+ var import_mongoose32 = __toESM(require("mongoose"));
9901
9955
  function normalizeObjectId(id) {
9902
- 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;
9903
9957
  }
9904
9958
  async function getAssociateEmailsForResource({
9905
9959
  normalizedResourceId,
@@ -10051,12 +10105,12 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
10051
10105
  }
10052
10106
 
10053
10107
  // src/service/objectIdToString.ts
10054
- var import_mongoose34 = __toESM(require("mongoose"));
10108
+ var import_mongoose35 = __toESM(require("mongoose"));
10055
10109
  function convertObjectIdsToStrings(obj) {
10056
10110
  if (obj === null || obj === void 0) {
10057
10111
  return obj;
10058
10112
  }
10059
- if (obj instanceof import_mongoose34.default.Types.ObjectId) {
10113
+ if (obj instanceof import_mongoose35.default.Types.ObjectId) {
10060
10114
  return obj.toString();
10061
10115
  }
10062
10116
  if (obj instanceof Date) {
@@ -10237,17 +10291,6 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
10237
10291
  };
10238
10292
  });
10239
10293
  }
10240
-
10241
- // src/types/index.ts
10242
- var import_express = __toESM(require("express"));
10243
- var import_mongoose37 = __toESM(require("mongoose"));
10244
- var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
10245
- EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
10246
- EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
10247
- EnumPubSubEvents2["GET_NOTIFICATIONS_COUNT"] = "GET_NOTIFICATIONS_COUNT";
10248
- EnumPubSubEvents2["USER_TYPING"] = "USER_TYPING";
10249
- return EnumPubSubEvents2;
10250
- })(EnumPubSubEvents || {});
10251
10294
  // Annotate the CommonJS export names for ESM import in node:
10252
10295
  0 && (module.exports = {
10253
10296
  ACTIVE_NOT_DELETED_FILTER,
@@ -10301,6 +10344,8 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
10301
10344
  mongoose,
10302
10345
  normalizeAffiliatePromoCodes,
10303
10346
  normalizePromoCode,
10347
+ notifyUsers,
10348
+ publishNotificationEvents,
10304
10349
  refundPolicySchema,
10305
10350
  relatedPostSchema,
10306
10351
  relationDatesSchema,