@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.
@@ -3,8 +3,8 @@ import { AdType, ReportChatUser, GoogleImportedMarket, PushTokenType, ResourceAc
3
3
  import mongoose__default from 'mongoose';
4
4
  import { O as ObjectId } from '../Chat-Bnqec74U.mjs';
5
5
  export { C as ChatModel, N as NotificationModel, a as SchemaChatMessageReactionType, S as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, e as SchemaChatType, f as SchemaCreateBulkNotificationInput, g as SchemaNotificationType, d as SchemaParticipantType } from '../Chat-Bnqec74U.mjs';
6
- import { S as SchemaOwnerType } from '../Affiliate-CmS0A1gU.mjs';
7
- export { A as AffiliateModel, C as CategorySchema, d as ContactDetailsSchema, O as OwnerTypeSchema, m as RelationModel, k as RelationTypeSchema, R as ResourceImageTypeSchema, o as SchemaAffiliateResourceType, n as SchemaAffiliateReward, a as SchemaRelatedPostType, j as SchemaRelationType, b as SocialMediaTypeSchema, c as associatesSchema, h as baseResourceFields, e as dateTimeSchema, l as locationGeoSchema, f as locationsSchema, g as relatedPostSchema, i as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-CmS0A1gU.mjs';
6
+ import { S as SchemaOwnerType } from '../Affiliate-6XcZ131C.mjs';
7
+ export { A as AffiliateModel, C as CategorySchema, d as ContactDetailsSchema, O as OwnerTypeSchema, m as RelationModel, k as RelationTypeSchema, R as ResourceImageTypeSchema, o as SchemaAffiliateResourceType, n as SchemaAffiliateReward, a as SchemaRelatedPostType, j as SchemaRelationType, b as SocialMediaTypeSchema, c as associatesSchema, h as baseResourceFields, e as dateTimeSchema, l as locationGeoSchema, f as locationsSchema, g as relatedPostSchema, i as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-6XcZ131C.mjs';
8
8
  import '@timardex/cluemart-shared/types';
9
9
  import 'express';
10
10
 
@@ -3,8 +3,8 @@ import { AdType, ReportChatUser, GoogleImportedMarket, PushTokenType, ResourceAc
3
3
  import mongoose__default from 'mongoose';
4
4
  import { O as ObjectId } from '../Chat-Bnqec74U.js';
5
5
  export { C as ChatModel, N as NotificationModel, a as SchemaChatMessageReactionType, S as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, e as SchemaChatType, f as SchemaCreateBulkNotificationInput, g as SchemaNotificationType, d as SchemaParticipantType } from '../Chat-Bnqec74U.js';
6
- import { S as SchemaOwnerType } from '../Affiliate-C_g6TdeG.js';
7
- export { A as AffiliateModel, C as CategorySchema, d as ContactDetailsSchema, O as OwnerTypeSchema, m as RelationModel, k as RelationTypeSchema, R as ResourceImageTypeSchema, o as SchemaAffiliateResourceType, n as SchemaAffiliateReward, a as SchemaRelatedPostType, j as SchemaRelationType, b as SocialMediaTypeSchema, c as associatesSchema, h as baseResourceFields, e as dateTimeSchema, l as locationGeoSchema, f as locationsSchema, g as relatedPostSchema, i as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-C_g6TdeG.js';
6
+ import { S as SchemaOwnerType } from '../Affiliate-DCvdeKW7.js';
7
+ export { A as AffiliateModel, C as CategorySchema, d as ContactDetailsSchema, O as OwnerTypeSchema, m as RelationModel, k as RelationTypeSchema, R as ResourceImageTypeSchema, o as SchemaAffiliateResourceType, n as SchemaAffiliateReward, a as SchemaRelatedPostType, j as SchemaRelationType, b as SocialMediaTypeSchema, c as associatesSchema, h as baseResourceFields, e as dateTimeSchema, l as locationGeoSchema, f as locationsSchema, g as relatedPostSchema, i as relationDatesSchema, r as resourceRelationsSchema, s as socialShareResourceSchema, t as termsAgreementSchema, u as userLicenseSchema } from '../Affiliate-DCvdeKW7.js';
8
8
  import '@timardex/cluemart-shared/types';
9
9
  import 'express';
10
10
 
@@ -40,7 +40,7 @@ import {
40
40
  socialShareResourceSchema,
41
41
  termsAgreementSchema,
42
42
  userLicenseSchema
43
- } from "../chunk-KRG2CATM.mjs";
43
+ } from "../chunk-IGEC5D7N.mjs";
44
44
  export {
45
45
  APP_SETTINGS_ID,
46
46
  AdModel,
@@ -44,6 +44,8 @@ __export(service_exports, {
44
44
  mapVendorLicenceToSubscriptionRewardType: () => mapVendorLicenceToSubscriptionRewardType,
45
45
  normalizeAffiliatePromoCodes: () => normalizeAffiliatePromoCodes,
46
46
  normalizePromoCode: () => normalizePromoCode,
47
+ notifyUsers: () => notifyUsers,
48
+ publishNotificationEvents: () => publishNotificationEvents,
47
49
  saveNotificationsInDb: () => saveNotificationsInDb,
48
50
  sendPushNotifications: () => sendPushNotifications,
49
51
  updateAdStatuses: () => updateAdStatuses,
@@ -8259,6 +8261,14 @@ var relatedPostSchema = new MongooseSchema6(
8259
8261
  { _id: false }
8260
8262
  // Prevents Mongoose from creating an additional _id field for subdocuments
8261
8263
  );
8264
+ var socialShareResourceSchema = new MongooseSchema6(
8265
+ {
8266
+ qrCode: { required: true, type: ResourceImageTypeSchema },
8267
+ socialImage: { required: true, type: ResourceImageTypeSchema }
8268
+ },
8269
+ { _id: false }
8270
+ // Prevents Mongoose from creating an additional _id field for subdocuments
8271
+ );
8262
8272
  var baseResourceFields = {
8263
8273
  active: { default: false, required: true, type: Boolean },
8264
8274
  adIds: {
@@ -8290,18 +8300,11 @@ var baseResourceFields = {
8290
8300
  region: { required: true, type: String },
8291
8301
  relatedPost: { required: false, type: relatedPostSchema },
8292
8302
  reviewCount: { required: false, type: Number },
8303
+ sharePublic: { required: false, type: socialShareResourceSchema },
8293
8304
  slug: { required: true, type: String },
8294
8305
  socialMedia: { required: false, type: [SocialMediaTypeSchema] },
8295
8306
  termsAgreement: { required: true, type: termsAgreementSchema }
8296
8307
  };
8297
- var socialShareResourceSchema = new MongooseSchema6(
8298
- {
8299
- qrCode: { required: true, type: ResourceImageTypeSchema },
8300
- socialImage: { required: true, type: ResourceImageTypeSchema }
8301
- },
8302
- { _id: false }
8303
- // Prevents Mongoose from creating an additional _id field for subdocuments
8304
- );
8305
8308
 
8306
8309
  // src/mongoose/GoogleImportedMarket.ts
8307
8310
  var import_mongoose7 = __toESM(require("mongoose"));
@@ -8778,7 +8781,6 @@ var schema9 = new MongooseSchema13(
8778
8781
  required: false,
8779
8782
  type: [resourceRelationsSchema]
8780
8783
  },
8781
- sharePublic: { required: false, type: socialShareResourceSchema },
8782
8784
  shareRelation: { required: false, type: socialShareResourceSchema },
8783
8785
  unregisteredVendorId: {
8784
8786
  ref: "UnregisteredVendor",
@@ -8931,7 +8933,6 @@ var schema12 = new MongooseSchema16(
8931
8933
  required: false,
8932
8934
  type: [resourceRelationsSchema]
8933
8935
  },
8934
- sharePublic: { required: false, type: socialShareResourceSchema },
8935
8936
  shareRelation: { required: false, type: socialShareResourceSchema },
8936
8937
  tags: { required: true, type: [String] }
8937
8938
  },
@@ -8963,8 +8964,7 @@ var schema13 = new MongooseSchema17(
8963
8964
  enum: Object.values(EnumPartnerType),
8964
8965
  required: true,
8965
8966
  type: String
8966
- },
8967
- sharePublic: { required: false, type: socialShareResourceSchema }
8967
+ }
8968
8968
  },
8969
8969
  { timestamps: true }
8970
8970
  );
@@ -9817,6 +9817,53 @@ var connectToDatabase = async ({
9817
9817
  }
9818
9818
  };
9819
9819
 
9820
+ // src/types/index.ts
9821
+ var import_express = __toESM(require("express"));
9822
+ var import_mongoose30 = __toESM(require("mongoose"));
9823
+
9824
+ // src/service/notifyUsers.ts
9825
+ async function publishNotificationEvents(userId, pubsub) {
9826
+ try {
9827
+ const userNotifications = await NotificationModel.find({
9828
+ userId
9829
+ }).sort({ createdAt: -1 });
9830
+ const [total, unread] = await Promise.all([
9831
+ NotificationModel.countDocuments({ userId }),
9832
+ NotificationModel.countDocuments({ isRead: false, userId })
9833
+ ]);
9834
+ pubsub.publish("GET_NOTIFICATIONS" /* GET_NOTIFICATIONS */, {
9835
+ getNotifications: userNotifications,
9836
+ getNotificationsUserId: userId
9837
+ });
9838
+ pubsub.publish("GET_NOTIFICATIONS_COUNT" /* GET_NOTIFICATIONS_COUNT */, {
9839
+ getNotificationsCount: { total, unread, userId }
9840
+ });
9841
+ console.log(`Published notification events for user: ${String(userId)}`);
9842
+ } catch (error) {
9843
+ console.error(
9844
+ `Failed to publish notification events for user ${String(userId)}:`,
9845
+ error
9846
+ );
9847
+ }
9848
+ }
9849
+ async function notifyUsers({
9850
+ payload,
9851
+ pubsub
9852
+ }) {
9853
+ try {
9854
+ await sendPushNotifications(payload);
9855
+ const uniqueUserIds = await saveNotificationsInDb(payload);
9856
+ if (!pubsub) {
9857
+ return;
9858
+ }
9859
+ for (const userId of uniqueUserIds) {
9860
+ await publishNotificationEvents(userId, pubsub);
9861
+ }
9862
+ } catch (error) {
9863
+ console.error("Error in notifyUsers:", error);
9864
+ }
9865
+ }
9866
+
9820
9867
  // src/service/updateAdStatus.ts
9821
9868
  async function updateAdStatuses() {
9822
9869
  const now = /* @__PURE__ */ new Date();
@@ -9853,9 +9900,9 @@ async function updateAdStatuses() {
9853
9900
  }
9854
9901
 
9855
9902
  // src/service/associate.ts
9856
- var import_mongoose31 = __toESM(require("mongoose"));
9903
+ var import_mongoose32 = __toESM(require("mongoose"));
9857
9904
  function normalizeObjectId(id) {
9858
- return typeof id === "string" ? new import_mongoose31.default.Types.ObjectId(id) : id;
9905
+ return typeof id === "string" ? new import_mongoose32.default.Types.ObjectId(id) : id;
9859
9906
  }
9860
9907
  async function getAssociateEmailsForResource({
9861
9908
  normalizedResourceId,
@@ -10007,12 +10054,12 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
10007
10054
  }
10008
10055
 
10009
10056
  // src/service/objectIdToString.ts
10010
- var import_mongoose34 = __toESM(require("mongoose"));
10057
+ var import_mongoose35 = __toESM(require("mongoose"));
10011
10058
  function convertObjectIdsToStrings(obj) {
10012
10059
  if (obj === null || obj === void 0) {
10013
10060
  return obj;
10014
10061
  }
10015
- if (obj instanceof import_mongoose34.default.Types.ObjectId) {
10062
+ if (obj instanceof import_mongoose35.default.Types.ObjectId) {
10016
10063
  return obj.toString();
10017
10064
  }
10018
10065
  if (obj instanceof Date) {
@@ -10209,6 +10256,8 @@ function updateRelationDatesToUnavailable(relationDates, eventDateTime) {
10209
10256
  mapVendorLicenceToSubscriptionRewardType,
10210
10257
  normalizeAffiliatePromoCodes,
10211
10258
  normalizePromoCode,
10259
+ notifyUsers,
10260
+ publishNotificationEvents,
10212
10261
  saveNotificationsInDb,
10213
10262
  sendPushNotifications,
10214
10263
  updateAdStatuses,