@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/{chunk-HLRUWJLN.mjs → chunk-ZKHRT2PV.mjs} +16 -8
- package/dist/chunk-ZKHRT2PV.mjs.map +1 -0
- package/dist/index.cjs +36 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -13
- package/dist/index.d.ts +5 -13
- package/dist/index.mjs +36 -97
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +15 -7
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +36 -96
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +5 -13
- package/dist/service/index.d.ts +5 -13
- package/dist/service/index.mjs +22 -91
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-HLRUWJLN.mjs.map +0 -1
package/dist/mongoose/index.mjs
CHANGED
package/dist/service/index.cjs
CHANGED
|
@@ -91,7 +91,7 @@ __export(service_exports, {
|
|
|
91
91
|
updateAdStatuses: () => updateAdStatuses,
|
|
92
92
|
updateAllEventDateTimeStatuses: () => updateAllEventDateTimeStatuses,
|
|
93
93
|
updateRelationDatesToUnavailable: () => updateRelationDatesToUnavailable,
|
|
94
|
-
updateSingleDateTimeStatus: () => updateSingleDateTimeStatus,
|
|
94
|
+
updateSingleDateTimeStatus: () => import_cluemart_shared34.updateSingleDateTimeStatus,
|
|
95
95
|
upgradeUserToLicence: () => upgradeUserToLicence,
|
|
96
96
|
vendorOwnerHasProLicence: () => vendorOwnerHasProLicence
|
|
97
97
|
});
|
|
@@ -1118,16 +1118,24 @@ var GoogleImportedMarketModel = import_mongoose10.default.models.GoogleImportedM
|
|
|
1118
1118
|
var import_cluemart_shared9 = require("@timardex/cluemart-shared");
|
|
1119
1119
|
var import_mongoose11 = __toESM(require("mongoose"));
|
|
1120
1120
|
var MongooseSchema7 = import_mongoose11.default.Schema;
|
|
1121
|
+
var notificationDataSchema = new MongooseSchema7(
|
|
1122
|
+
{
|
|
1123
|
+
resourceId: { required: true, type: String },
|
|
1124
|
+
resourceName: { required: true, type: String },
|
|
1125
|
+
resourceType: {
|
|
1126
|
+
enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
|
|
1127
|
+
required: true,
|
|
1128
|
+
type: String
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
{ _id: false }
|
|
1132
|
+
);
|
|
1121
1133
|
var schema8 = new MongooseSchema7(
|
|
1122
1134
|
{
|
|
1123
1135
|
data: {
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
enum: Object.values(import_cluemart_shared9.EnumNotificationResourceType),
|
|
1128
|
-
required: true,
|
|
1129
|
-
type: String
|
|
1130
|
-
}
|
|
1136
|
+
default: null,
|
|
1137
|
+
required: false,
|
|
1138
|
+
type: notificationDataSchema
|
|
1131
1139
|
},
|
|
1132
1140
|
isRead: { default: false, index: true, required: true, type: Boolean },
|
|
1133
1141
|
message: { required: true, type: String },
|
|
@@ -2529,25 +2537,24 @@ var import_utils3 = require("@timardex/cluemart-shared/utils");
|
|
|
2529
2537
|
// src/service/saveNotificationsInDb.ts
|
|
2530
2538
|
async function saveNotificationsInDb(payload) {
|
|
2531
2539
|
const { data, message, title, type, userIds } = payload;
|
|
2532
|
-
|
|
2540
|
+
const notifications = userIds.map((userId) => ({
|
|
2541
|
+
data,
|
|
2542
|
+
isRead: false,
|
|
2543
|
+
message,
|
|
2544
|
+
title,
|
|
2545
|
+
type,
|
|
2546
|
+
userId
|
|
2547
|
+
}));
|
|
2533
2548
|
try {
|
|
2534
|
-
const notifications = userIds.map((userId) => ({
|
|
2535
|
-
data,
|
|
2536
|
-
isRead: false,
|
|
2537
|
-
message,
|
|
2538
|
-
title,
|
|
2539
|
-
type,
|
|
2540
|
-
userId
|
|
2541
|
-
}));
|
|
2542
2549
|
await NotificationModel.insertMany(notifications);
|
|
2543
|
-
console.log(
|
|
2544
|
-
`Created ${notifications.length} notifications for ${userIds.length} users`
|
|
2545
|
-
);
|
|
2546
|
-
return [...new Set(userIds)];
|
|
2547
2550
|
} catch (error) {
|
|
2548
2551
|
console.error("Failed to create notifications:", error);
|
|
2549
|
-
|
|
2552
|
+
throw error;
|
|
2550
2553
|
}
|
|
2554
|
+
console.log(
|
|
2555
|
+
`Created ${notifications.length} notifications for ${userIds.length} users`
|
|
2556
|
+
);
|
|
2557
|
+
return [...new Set(userIds)];
|
|
2551
2558
|
}
|
|
2552
2559
|
|
|
2553
2560
|
// src/service/sendPushNotifications.ts
|
|
@@ -2571,7 +2578,7 @@ function createPushMessages({
|
|
|
2571
2578
|
}
|
|
2572
2579
|
messages.push({
|
|
2573
2580
|
body: message,
|
|
2574
|
-
data: { ...data },
|
|
2581
|
+
...data ? { data: { ...data } } : {},
|
|
2575
2582
|
sound: "tui.wav",
|
|
2576
2583
|
title,
|
|
2577
2584
|
to: token
|
|
@@ -2626,7 +2633,6 @@ async function sendPushNotifications({
|
|
|
2626
2633
|
}) {
|
|
2627
2634
|
const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
|
|
2628
2635
|
const expoTokens = pushTokens.map((token) => token.token);
|
|
2629
|
-
if (!data) return;
|
|
2630
2636
|
const { messages, invalidTokens } = createPushMessages({
|
|
2631
2637
|
data,
|
|
2632
2638
|
message,
|
|
@@ -3099,8 +3105,6 @@ function convertObjectIdsToStrings(obj) {
|
|
|
3099
3105
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3100
3106
|
var import_cluemart_shared26 = require("@timardex/cluemart-shared");
|
|
3101
3107
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
3102
|
-
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
3103
|
-
var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
|
|
3104
3108
|
|
|
3105
3109
|
// src/service/event/archiveEndedEventDates.ts
|
|
3106
3110
|
var import_cluemart_shared25 = require("@timardex/cluemart-shared");
|
|
@@ -3143,73 +3147,6 @@ async function persistArchivedEventDates(eventId, slots) {
|
|
|
3143
3147
|
}
|
|
3144
3148
|
|
|
3145
3149
|
// src/service/event/updateAllEventDateTimeStatuses.ts
|
|
3146
|
-
import_dayjs2.default.extend(import_customParseFormat.default);
|
|
3147
|
-
import_dayjs2.default.extend(import_isoWeek.default);
|
|
3148
|
-
var MANUAL_DATE_STATUSES = /* @__PURE__ */ new Set([
|
|
3149
|
-
import_cluemart_shared26.EnumEventDateStatus.CANCELED,
|
|
3150
|
-
import_cluemart_shared26.EnumEventDateStatus.RE_SCHEDULED
|
|
3151
|
-
]);
|
|
3152
|
-
function getFutureEventStatus(startDateTime, now) {
|
|
3153
|
-
const hoursUntilStart = startDateTime.diff(now, "hour", true);
|
|
3154
|
-
if (hoursUntilStart > 0 && hoursUntilStart <= 4) {
|
|
3155
|
-
return import_cluemart_shared26.EnumEventDateStatus.STARTING_SOON;
|
|
3156
|
-
}
|
|
3157
|
-
if (startDateTime.isSame(now, "day")) {
|
|
3158
|
-
return import_cluemart_shared26.EnumEventDateStatus.TODAY;
|
|
3159
|
-
}
|
|
3160
|
-
if (startDateTime.isSame(now.add(1, "day"), "day")) {
|
|
3161
|
-
return import_cluemart_shared26.EnumEventDateStatus.TOMORROW;
|
|
3162
|
-
}
|
|
3163
|
-
if (startDateTime.isSame(now, "isoWeek")) {
|
|
3164
|
-
return import_cluemart_shared26.EnumEventDateStatus.THIS_WEEK;
|
|
3165
|
-
}
|
|
3166
|
-
if (startDateTime.isSame(now.add(1, "week"), "isoWeek")) {
|
|
3167
|
-
return import_cluemart_shared26.EnumEventDateStatus.NEXT_WEEK;
|
|
3168
|
-
}
|
|
3169
|
-
return import_cluemart_shared26.EnumEventDateStatus.UPCOMING;
|
|
3170
|
-
}
|
|
3171
|
-
function updateSingleDateTimeStatus(dateTime, now = (0, import_dayjs2.default)()) {
|
|
3172
|
-
if (MANUAL_DATE_STATUSES.has(dateTime.dateStatus)) {
|
|
3173
|
-
return dateTime;
|
|
3174
|
-
}
|
|
3175
|
-
const dateTimeFormat = `${import_cluemart_shared26.dateFormat} ${import_cluemart_shared26.timeFormat}`;
|
|
3176
|
-
const startDateTime = (0, import_dayjs2.default)(
|
|
3177
|
-
`${dateTime.startDate} ${dateTime.startTime}`,
|
|
3178
|
-
dateTimeFormat,
|
|
3179
|
-
true
|
|
3180
|
-
);
|
|
3181
|
-
const endDateTime = (0, import_dayjs2.default)(
|
|
3182
|
-
`${dateTime.endDate} ${dateTime.endTime}`,
|
|
3183
|
-
dateTimeFormat,
|
|
3184
|
-
true
|
|
3185
|
-
);
|
|
3186
|
-
if (!startDateTime.isValid() || !endDateTime.isValid()) {
|
|
3187
|
-
return {
|
|
3188
|
-
...dateTime,
|
|
3189
|
-
dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
|
|
3190
|
-
};
|
|
3191
|
-
}
|
|
3192
|
-
if (endDateTime.isBefore(startDateTime)) {
|
|
3193
|
-
return {
|
|
3194
|
-
...dateTime,
|
|
3195
|
-
dateStatus: import_cluemart_shared26.EnumEventDateStatus.INVALID
|
|
3196
|
-
};
|
|
3197
|
-
}
|
|
3198
|
-
let dateStatus;
|
|
3199
|
-
if (endDateTime.isAfter(now)) {
|
|
3200
|
-
if (startDateTime.isAfter(now)) {
|
|
3201
|
-
dateStatus = getFutureEventStatus(startDateTime, now);
|
|
3202
|
-
} else {
|
|
3203
|
-
dateStatus = import_cluemart_shared26.EnumEventDateStatus.STARTED;
|
|
3204
|
-
}
|
|
3205
|
-
} else {
|
|
3206
|
-
dateStatus = import_cluemart_shared26.EnumEventDateStatus.ENDED;
|
|
3207
|
-
}
|
|
3208
|
-
return {
|
|
3209
|
-
...dateTime,
|
|
3210
|
-
dateStatus
|
|
3211
|
-
};
|
|
3212
|
-
}
|
|
3213
3150
|
var dateTimeStatusFilter = {
|
|
3214
3151
|
dateTime: { $ne: [], $type: "array" },
|
|
3215
3152
|
deletedAt: null
|
|
@@ -3238,7 +3175,7 @@ async function updateModelDateTimeStatuses(model, now) {
|
|
|
3238
3175
|
try {
|
|
3239
3176
|
for await (const doc of cursor) {
|
|
3240
3177
|
const dateTime = doc.dateTime.map(
|
|
3241
|
-
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3178
|
+
(slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
|
|
3242
3179
|
);
|
|
3243
3180
|
if (!hasDateTimeStatusChanges(doc.dateTime, dateTime)) {
|
|
3244
3181
|
continue;
|
|
@@ -3283,7 +3220,7 @@ async function archiveEndedAndDiscardInvalidEventDates(now) {
|
|
|
3283
3220
|
try {
|
|
3284
3221
|
for await (const doc of cursor) {
|
|
3285
3222
|
const updated = doc.dateTime.map(
|
|
3286
|
-
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3223
|
+
(slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
|
|
3287
3224
|
);
|
|
3288
3225
|
const { archive, discard } = splitEventDatesForArchive(updated);
|
|
3289
3226
|
if (archive.length === 0 && discard.length === 0) {
|
|
@@ -3341,7 +3278,7 @@ async function cleanEventInfoDates(now) {
|
|
|
3341
3278
|
try {
|
|
3342
3279
|
for await (const doc of cursor) {
|
|
3343
3280
|
const updated = doc.dateTime.map(
|
|
3344
|
-
(slot) => updateSingleDateTimeStatus(slot, now)
|
|
3281
|
+
(slot) => (0, import_cluemart_shared26.updateSingleDateTimeStatus)(slot, now)
|
|
3345
3282
|
);
|
|
3346
3283
|
const kept = (0, import_cluemart_shared26.filterDatesByFutureStatus)(updated);
|
|
3347
3284
|
if (kept.length === updated.length) {
|
|
@@ -3388,6 +3325,9 @@ async function updateAllEventDateTimeStatuses() {
|
|
|
3388
3325
|
}
|
|
3389
3326
|
}
|
|
3390
3327
|
|
|
3328
|
+
// src/service/index.ts
|
|
3329
|
+
var import_cluemart_shared34 = require("@timardex/cluemart-shared");
|
|
3330
|
+
|
|
3391
3331
|
// src/service/event/findEventOrImportedMarketById.ts
|
|
3392
3332
|
async function findEventOrImportedMarketById(resourceId) {
|
|
3393
3333
|
if (!resourceId) {
|