@timardex/cluemart-server-shared 2.2.0 → 2.2.12

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
@@ -145,7 +145,7 @@ __export(index_exports, {
145
145
  updateAdStatuses: () => updateAdStatuses,
146
146
  updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
147
147
  updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
148
- updateSingleDateTimeStatus: () => updateSingleDateTimeStatus,
148
+ updateSingleDateTimeStatus: () => import_cluemart_shared34.updateSingleDateTimeStatus,
149
149
  upgradeUserToLicence: () => upgradeUserToLicence,
150
150
  userLicenseSchema: () => userLicenseSchema,
151
151
  vendorOwnerHasProLicence: () => vendorOwnerHasProLicence,
@@ -1202,16 +1202,24 @@ var GoogleImportedMarketModel = import_mongoose10.default.models.GoogleImportedM
1202
1202
  var import_cluemart_shared9 = require("@timardex/cluemart-shared");
1203
1203
  var import_mongoose11 = __toESM(require("mongoose"));
1204
1204
  var MongooseSchema7 = import_mongoose11.default.Schema;
1205
+ var notificationDataSchema = new MongooseSchema7(
1206
+ {
1207
+ resourceId: { required: true, type: String },
1208
+ resourceName: { required: true, type: String },
1209
+ resourceType: {
1210
+ enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1211
+ required: true,
1212
+ type: String
1213
+ }
1214
+ },
1215
+ { _id: false }
1216
+ );
1205
1217
  var schema8 = new MongooseSchema7(
1206
1218
  {
1207
1219
  data: {
1208
- resourceId: { required: true, type: String },
1209
- resourceName: { required: true, type: String },
1210
- resourceType: {
1211
- enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
1212
- required: true,
1213
- type: String
1214
- }
1220
+ default: null,
1221
+ required: false,
1222
+ type: notificationDataSchema
1215
1223
  },
1216
1224
  isRead: { default: false, index: true, required: true, type: Boolean },
1217
1225
  message: { required: true, type: String },
@@ -2613,25 +2621,24 @@ var import_utils3 = require("@timardex/cluemart-shared/utils");
2613
2621
  // src/service/saveNotificationsInDb.ts
2614
2622
  async function saveNotificationsInDb(payload) {
2615
2623
  const { data, message, title, type, userIds } = payload;
2616
- console.log("NOTIFICATION DATA", JSON.stringify(payload, null, 2));
2624
+ const notifications = userIds.map((userId) => ({
2625
+ data,
2626
+ isRead: false,
2627
+ message,
2628
+ title,
2629
+ type,
2630
+ userId
2631
+ }));
2617
2632
  try {
2618
- const notifications = userIds.map((userId) => ({
2619
- data,
2620
- isRead: false,
2621
- message,
2622
- title,
2623
- type,
2624
- userId
2625
- }));
2626
2633
  await NotificationModel.insertMany(notifications);
2627
- console.log(
2628
- `Created ${notifications.length} notifications for ${userIds.length} users`
2629
- );
2630
- return [...new Set(userIds)];
2631
2634
  } catch (error) {
2632
2635
  console.error("Failed to create notifications:", error);
2633
- return [];
2636
+ throw error;
2634
2637
  }
2638
+ console.log(
2639
+ `Created ${notifications.length} notifications for ${userIds.length} users`
2640
+ );
2641
+ return [...new Set(userIds)];
2635
2642
  }
2636
2643
 
2637
2644
  // src/service/sendPushNotifications.ts
@@ -2655,7 +2662,7 @@ function createPushMessages({
2655
2662
  }
2656
2663
  messages.push({
2657
2664
  body: message,
2658
- data: { ...data },
2665
+ ...data ? { data: { ...data } } : {},
2659
2666
  sound: "tui.wav",
2660
2667
  title,
2661
2668
  to: token
@@ -2710,7 +2717,6 @@ async function sendPushNotifications({
2710
2717
  }) {
2711
2718
  const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
2712
2719
  const expoTokens = pushTokens.map((token) => token.token);
2713
- if (!data) return;
2714
2720
  const { messages, invalidTokens } = createPushMessages({
2715
2721
  data,
2716
2722
  message,
@@ -3190,8 +3196,6 @@ function convertObjectIdsToStrings(obj) {
3190
3196
  // src/service/event/updateAllEventDateTimeStatuses.ts
3191
3197
  var import_cluemart_shared26 = require("@timardex/cluemart-shared");
3192
3198
  var import_dayjs2 = __toESM(require("dayjs"));
3193
- var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
3194
- var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
3195
3199
 
3196
3200
  // src/service/event/archiveEndedEventDates.ts
3197
3201
  var import_cluemart_shared25 = require("@timardex/cluemart-shared");
@@ -3234,73 +3238,6 @@ async function persistArchivedEventDates(eventId, slots) {
3234
3238
  }
3235
3239
 
3236
3240
  // src/service/event/updateAllEventDateTimeStatuses.ts
3237
- import_dayjs2.default.extend(import_customParseFormat.default);
3238
- import_dayjs2.default.extend(import_isoWeek.default);
3239
- var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
3240
- import_cluemart_shared26.EnumEventDateStatus.CANCELED,
3241
- import_cluemart_shared26.EnumEventDateStatus.RE_SCHEDULED
3242
- ]);
3243
- function getFutureEventStatus(startDateTime, now) {
3244
- const hoursUntilStart = startDateTime.diff(now, "hour", true);
3245
- if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
3246
- return import_cluemart_shared26.EnumEventDateStatus.STARTING_SOON;
3247
- }
3248
- if (startDateTime.isSame(now, "day")) {
3249
- return import_cluemart_shared26.EnumEventDateStatus.TODAY;
3250
- }
3251
- if (startDateTime.isSame(now.add(1, "day"), "day")) {
3252
- return import_cluemart_shared26.EnumEventDateStatus.TOMORROW;
3253
- }
3254
- if (startDateTime.isSame(now, "isoWeek")) {
3255
- return import_cluemart_shared26.EnumEventDateStatus.THIS_WEEK;
3256
- }
3257
- if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
3258
- return import_cluemart_shared26.EnumEventDateStatus.NEXT_WEEK;
3259
- }
3260
- return import_cluemart_shared26.EnumEventDateStatus.UPCOMING;
3261
- }
3262
- function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
3263
- if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
3264
- return dateTime;
3265
- }
3266
- const dateTimeFormat = `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`;
3267
- const startDateTime = (0, import_dayjs2.default)(
3268
- `${dateTime.startDate} ${dateTime.startTime}`,
3269
- dateTimeFormat,
3270
- true
3271
- );
3272
- const endDateTime = (0, import_dayjs2.default)(
3273
- `${dateTime.endDate} ${dateTime.endTime}`,
3274
- dateTimeFormat,
3275
- true
3276
- );
3277
- if (!startDateTime.isValid() || !endDateTime.isValid()) {
3278
- return {
3279
- ...dateTime,
3280
- dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
3281
- };
3282
- }
3283
- if (endDateTime.isBefore(startDateTime)) {
3284
- return {
3285
- ...dateTime,
3286
- dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
3287
- };
3288
- }
3289
- let dateStatus;
3290
- if (endDateTime.isAfter(now)) {
3291
- if (startDateTime.isAfter(now)) {
3292
- dateStatus = getFutureEventStatus(startDateTime, now);
3293
- } else {
3294
- dateStatus = import_cluemart_shared26.EnumEventDateStatus.STARTED;
3295
- }
3296
- } else {
3297
- dateStatus = import_cluemart_shared26.EnumEventDateStatus.ENDED;
3298
- }
3299
- return {
3300
- ...dateTime,
3301
- dateStatus
3302
- };
3303
- }
3304
3241
  var dateTimeStatusFilter = {
3305
3242
  dateTime: { $ne: [], $type: "array" },
3306
3243
  deletedAt: null
@@ -3329,7 +3266,7 @@ async function updateModelDateTimeStatuses(model, now) {
3329
3266
  try {
3330
3267
  for await (const doc of cursor) {
3331
3268
  const dateTime = doc.dateTime.map(
3332
- (slot) => updateSingleDateTimeStatus(slot, now)
3269
+ (slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
3333
3270
  );
3334
3271
  if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
3335
3272
  continue;
@@ -3374,7 +3311,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
3374
3311
  try {
3375
3312
  for await (const doc of cursor) {
3376
3313
  const updated = doc.dateTime.map(
3377
- (slot) => updateSingleDateTimeStatus(slot, now)
3314
+ (slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
3378
3315
  );
3379
3316
  const { archive, discard } = splitEventDatesForArchive(updated);
3380
3317
  if (archive.length === 0 && discard.length === 0) {
@@ -3432,7 +3369,7 @@ async function cleanEventInfoDates(now) {
3432
3369
  try {
3433
3370
  for await (const doc of cursor) {
3434
3371
  const updated = doc.dateTime.map(
3435
- (slot) => updateSingleDateTimeStatus(slot, now)
3372
+ (slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
3436
3373
  );
3437
3374
  const kept = (0, import_cluemart_shared26.filterDatesByFutureStatus)(updated);
3438
3375
  if (kept.length === updated.length) {
@@ -3479,6 +3416,9 @@ async function updateAllEventDateTimeStatuses() {
3479
3416
  }
3480
3417
  }
3481
3418
 
3419
+ // src/service/index.ts
3420
+ var import_cluemart_shared34 = require("@timardex/cluemart-shared");
3421
+
3482
3422
  // src/service/event/findEventOrImportedMarketById.ts
3483
3423
  async function findEventOrImportedMarketById(resourceId) {
3484
3424
  if (!resourceId) {