@timardex/cluemart-server-shared 1.0.3 → 1.0.4

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,1139 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/service/index.ts
31
+ var service_exports = {};
32
+ __export(service_exports, {
33
+ connectToDatabase: () => connectToDatabase,
34
+ saveNotificationsInDb: () => saveNotificationsInDb,
35
+ sendPushNotifications: () => sendPushNotifications,
36
+ updateAdStatuses: () => updateAdStatuses
37
+ });
38
+ module.exports = __toCommonJS(service_exports);
39
+
40
+ // src/service/database.ts
41
+ var import_mongoose = __toESM(require("mongoose"));
42
+
43
+ // src/service/timezonePlugin.ts
44
+ var import_dayjs = __toESM(require("dayjs"));
45
+ var import_timezone = __toESM(require("dayjs/plugin/timezone"));
46
+ var import_utc = __toESM(require("dayjs/plugin/utc"));
47
+ import_dayjs.default.extend(import_utc.default);
48
+ import_dayjs.default.extend(import_timezone.default);
49
+ function timezonePlugin(schema11) {
50
+ if (!schema11.get("timestamps")) return;
51
+ const transform = (_doc, ret) => {
52
+ if (ret.createdAt)
53
+ ret.createdAt = (0, import_dayjs.default)(ret.createdAt).tz("Pacific/Auckland").format();
54
+ if (ret.updatedAt)
55
+ ret.updatedAt = (0, import_dayjs.default)(ret.updatedAt).tz("Pacific/Auckland").format();
56
+ return ret;
57
+ };
58
+ schema11.set("toJSON", { transform });
59
+ schema11.set("toObject", { transform });
60
+ }
61
+
62
+ // src/service/database.ts
63
+ import_mongoose.default.plugin(timezonePlugin);
64
+ var connectToDatabase = async ({
65
+ appName,
66
+ dbName,
67
+ dbPassword,
68
+ dbUser,
69
+ mongodbUri
70
+ }) => {
71
+ try {
72
+ const mongoUri = mongodbUri ? mongodbUri : (
73
+ // Fallback to MongoDB Atlas connection string
74
+ `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
75
+ );
76
+ await import_mongoose.default.connect(mongoUri);
77
+ const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
78
+ console.log(
79
+ `${connectionType} connected from server/src/service/database.ts`
80
+ );
81
+ } catch (err) {
82
+ console.error("Error connecting to MongoDB:", err);
83
+ throw err;
84
+ }
85
+ };
86
+
87
+ // src/mongoose/Notification.ts
88
+ var import_cluemart_shared = require("@timardex/cluemart-shared");
89
+ var import_mongoose2 = __toESM(require("mongoose"));
90
+ var MongooseSchema = import_mongoose2.default.Schema;
91
+ var schema = new MongooseSchema(
92
+ {
93
+ data: {
94
+ resourceId: { required: true, type: String },
95
+ resourceName: { required: true, type: String },
96
+ resourceType: {
97
+ enum: Object.values(import_cluemart_shared.EnumNotificationResourceType),
98
+ required: true,
99
+ type: String
100
+ }
101
+ },
102
+ isRead: { default: false, index: true, required: true, type: Boolean },
103
+ message: { required: true, type: String },
104
+ title: { required: true, type: String },
105
+ type: {
106
+ default: import_cluemart_shared.EnumNotificationType.SYSTEM,
107
+ enum: Object.values(import_cluemart_shared.EnumNotificationType),
108
+ required: true,
109
+ type: String
110
+ },
111
+ userId: {
112
+ ref: "User",
113
+ required: true,
114
+ type: import_mongoose2.default.Schema.Types.ObjectId
115
+ }
116
+ },
117
+ { timestamps: true }
118
+ );
119
+ schema.index({ isRead: 1, userId: 1 });
120
+ schema.index({ createdAt: -1, userId: 1 });
121
+ var NotificationModel = import_mongoose2.default.models.Notification || import_mongoose2.default.model("Notification", schema);
122
+
123
+ // src/service/saveNotificationsInDb.ts
124
+ async function saveNotificationsInDb(payload) {
125
+ const { data, message, title, type, userIds } = payload;
126
+ try {
127
+ const notifications = userIds.map((userId) => ({
128
+ data,
129
+ isRead: false,
130
+ message,
131
+ title,
132
+ type,
133
+ userId
134
+ }));
135
+ await NotificationModel.insertMany(notifications);
136
+ console.log(
137
+ `Created ${notifications.length} notifications for ${userIds.length} users`
138
+ );
139
+ return [...new Set(userIds)];
140
+ } catch (error) {
141
+ console.error("Failed to create notifications:", error);
142
+ return [];
143
+ }
144
+ }
145
+
146
+ // src/service/sendPushNotifications.ts
147
+ var import_expo_server_sdk = require("expo-server-sdk");
148
+
149
+ // src/mongoose/PushToken.ts
150
+ var import_enums = require("@timardex/cluemart-shared/enums");
151
+ var import_mongoose3 = __toESM(require("mongoose"));
152
+ var MongooseSchema2 = import_mongoose3.default.Schema;
153
+ var schema2 = new MongooseSchema2(
154
+ {
155
+ platform: {
156
+ enum: Object.values(import_enums.EnumOSPlatform),
157
+ required: true,
158
+ type: String
159
+ },
160
+ token: { required: true, type: String },
161
+ userId: { required: true, type: import_mongoose3.default.Schema.Types.ObjectId }
162
+ },
163
+ { timestamps: true }
164
+ );
165
+ var PushTokenModel = import_mongoose3.default.models.PushToken || import_mongoose3.default.model("PushToken", schema2);
166
+
167
+ // src/service/sendPushNotifications.ts
168
+ var expo = new import_expo_server_sdk.Expo();
169
+ function extractTokensFromMessage(message) {
170
+ return Array.isArray(message.to) ? message.to : [message.to];
171
+ }
172
+ function createPushMessages({
173
+ tokens,
174
+ message,
175
+ title,
176
+ data
177
+ }) {
178
+ const messages = [];
179
+ const invalidTokens = [];
180
+ for (const token of tokens) {
181
+ if (!import_expo_server_sdk.Expo.isExpoPushToken(token)) {
182
+ invalidTokens.push(token);
183
+ continue;
184
+ }
185
+ messages.push({
186
+ body: message,
187
+ data: { ...data },
188
+ sound: "default",
189
+ title,
190
+ to: token
191
+ });
192
+ }
193
+ return { invalidTokens, messages };
194
+ }
195
+ function processChunkResults(tickets, chunk) {
196
+ let successCount = 0;
197
+ const failedTokens = [];
198
+ for (const [ticketIndex, ticket] of tickets.entries()) {
199
+ if (ticket.status === "error") {
200
+ const message = chunk[ticketIndex];
201
+ if (message) {
202
+ const tokens = extractTokensFromMessage(message);
203
+ if (ticket.details?.error === "DeviceNotRegistered") {
204
+ failedTokens.push(...tokens);
205
+ }
206
+ console.log("Push notification error", {
207
+ error: ticket.details?.error,
208
+ tokens
209
+ });
210
+ }
211
+ } else {
212
+ successCount++;
213
+ }
214
+ }
215
+ return { failedTokens, successCount };
216
+ }
217
+ async function sendChunk(chunk, chunkIndex) {
218
+ try {
219
+ const tickets = await expo.sendPushNotificationsAsync(chunk);
220
+ const { successCount, failedTokens } = processChunkResults(tickets, chunk);
221
+ console.log(
222
+ `Chunk ${chunkIndex + 1}: Sent ${successCount}/${chunk.length} notifications successfully`
223
+ );
224
+ return { failedTokens, successCount };
225
+ } catch (error) {
226
+ console.log("Error sending Expo push notification chunk", {
227
+ chunkIndex,
228
+ chunkSize: chunk.length,
229
+ error: error instanceof Error ? error.message : String(error)
230
+ });
231
+ return { failedTokens: [], successCount: 0 };
232
+ }
233
+ }
234
+ async function sendPushNotifications({
235
+ data,
236
+ message,
237
+ title,
238
+ userIds
239
+ }) {
240
+ const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
241
+ const expoTokens = pushTokens.map((token) => token.token);
242
+ if (!data) return;
243
+ const { messages, invalidTokens } = createPushMessages({
244
+ data,
245
+ message,
246
+ title,
247
+ tokens: expoTokens
248
+ });
249
+ if (invalidTokens.length > 0) {
250
+ console.log(`Found ${invalidTokens.length} invalid push tokens`);
251
+ }
252
+ if (messages.length === 0) {
253
+ console.log("No valid messages to send after filtering tokens");
254
+ return;
255
+ }
256
+ const chunks = expo.chunkPushNotifications(messages);
257
+ let totalSuccessCount = 0;
258
+ const allFailedTokens = [];
259
+ for (const [chunkIndex, chunk] of chunks.entries()) {
260
+ const { successCount, failedTokens } = await sendChunk(
261
+ chunk,
262
+ chunkIndex + 1
263
+ );
264
+ totalSuccessCount += successCount;
265
+ allFailedTokens.push(...failedTokens);
266
+ }
267
+ console.log(
268
+ `Sent push notification to ${totalSuccessCount}/${messages.length} tokens across ${chunks.length} chunks`
269
+ );
270
+ if (allFailedTokens.length > 0) {
271
+ console.log(`Found ${allFailedTokens.length} failed push tokens`);
272
+ }
273
+ }
274
+
275
+ // src/service/updateAdStatus.ts
276
+ var import_cluemart_shared13 = require("@timardex/cluemart-shared");
277
+
278
+ // src/mongoose/Ad.ts
279
+ var import_cluemart_shared5 = require("@timardex/cluemart-shared");
280
+ var import_mongoose7 = __toESM(require("mongoose"));
281
+
282
+ // src/mongoose/global.ts
283
+ var import_cluemart_shared4 = require("@timardex/cluemart-shared");
284
+ var import_mongoose6 = __toESM(require("mongoose"));
285
+
286
+ // src/mongoose/Relation.ts
287
+ var import_mongoose5 = __toESM(require("mongoose"));
288
+ var import_cluemart_shared3 = require("@timardex/cluemart-shared");
289
+
290
+ // src/mongoose/event/EventInfo.ts
291
+ var import_cluemart_shared2 = require("@timardex/cluemart-shared");
292
+ var import_mongoose4 = __toESM(require("mongoose"));
293
+ var MongooseSchema3 = import_mongoose4.default.Schema;
294
+ var StallTypeSchema = new MongooseSchema3(
295
+ {
296
+ electricity: {
297
+ price: { required: false, type: Number },
298
+ selected: { required: false, type: Boolean }
299
+ },
300
+ label: { required: false, type: String },
301
+ price: { required: false, type: Number },
302
+ stallCapacity: { required: false, type: Number }
303
+ },
304
+ {
305
+ _id: false
306
+ // Prevents Mongoose from creating an additional _id field for subdocuments
307
+ }
308
+ );
309
+ var dateTimeSchema = new MongooseSchema3(
310
+ {
311
+ endDate: { required: true, type: String },
312
+ endTime: { required: true, type: String },
313
+ stallTypes: [StallTypeSchema],
314
+ startDate: { required: true, type: String },
315
+ startTime: { required: true, type: String }
316
+ },
317
+ { _id: false }
318
+ // Prevents Mongoose from creating an additional _id field for subdocuments
319
+ );
320
+ var paymentInfoSchema = new MongooseSchema3(
321
+ {
322
+ accountHolderName: { required: false, type: String },
323
+ accountNumber: { required: false, type: String },
324
+ link: { required: false, type: String },
325
+ paymentMethod: {
326
+ enum: Object.values(import_cluemart_shared2.EnumPaymentMethod),
327
+ required: true,
328
+ type: String
329
+ }
330
+ },
331
+ { _id: false }
332
+ // Prevents Mongoose from creating an additional _id field
333
+ );
334
+ var requirementsSchema = new MongooseSchema3(
335
+ {
336
+ category: { required: true, type: String },
337
+ label: { required: true, type: String },
338
+ value: { required: true, type: Boolean }
339
+ },
340
+ {
341
+ _id: false
342
+ // Prevents Mongoose from creating an additional _id field for
343
+ }
344
+ );
345
+ var schema3 = new MongooseSchema3(
346
+ {
347
+ applicationDeadlineHours: { required: true, type: Number },
348
+ dateTime: [dateTimeSchema],
349
+ eventId: {
350
+ ref: "Event",
351
+ required: false,
352
+ type: import_mongoose4.default.Schema.Types.ObjectId
353
+ },
354
+ packInTime: { required: true, type: Number },
355
+ paymentDueHours: { required: true, type: Number },
356
+ paymentInfo: [paymentInfoSchema],
357
+ requirements: [requirementsSchema]
358
+ },
359
+ { timestamps: true }
360
+ );
361
+ var EventInfoModel = import_mongoose4.default.models.EventInfo || import_mongoose4.default.model("EventInfo", schema3);
362
+
363
+ // src/mongoose/Relation.ts
364
+ var MongooseSchema4 = import_mongoose5.default.Schema;
365
+ var relationDatesSchema = new MongooseSchema4(
366
+ {
367
+ lastUpdateBy: {
368
+ resourceId: { required: false, type: String },
369
+ userEmail: { required: false, type: String }
370
+ },
371
+ paymentReference: { required: false, type: String },
372
+ stallType: StallTypeSchema,
373
+ startDate: { required: false, type: String },
374
+ startTime: { required: false, type: String },
375
+ status: {
376
+ enum: Object.values(import_cluemart_shared3.EnumInviteStatus),
377
+ required: false,
378
+ type: String
379
+ }
380
+ },
381
+ { _id: false }
382
+ );
383
+ var RelationTypeSchema = new MongooseSchema4(
384
+ {
385
+ active: { default: true, required: true, type: Boolean },
386
+ chatId: {
387
+ ref: "Chat",
388
+ required: true,
389
+ type: import_mongoose5.default.Schema.Types.ObjectId
390
+ },
391
+ deletedAt: { default: null, required: false, type: Date },
392
+ eventId: {
393
+ ref: "Event",
394
+ required: true,
395
+ type: import_mongoose5.default.Schema.Types.ObjectId
396
+ },
397
+ lastUpdateBy: {
398
+ enum: Object.values(import_cluemart_shared3.EnumResourceType),
399
+ required: true,
400
+ type: String
401
+ },
402
+ relationDates: [relationDatesSchema],
403
+ relationType: {
404
+ enum: Object.values(import_cluemart_shared3.EnumRelationResource),
405
+ required: true,
406
+ type: String
407
+ },
408
+ vendorId: {
409
+ ref: "Vendor",
410
+ required: true,
411
+ type: import_mongoose5.default.Schema.Types.ObjectId
412
+ }
413
+ },
414
+ { timestamps: true }
415
+ );
416
+ RelationTypeSchema.index({
417
+ "relationDates.startDate": 1,
418
+ "relationDates.startTime": 1,
419
+ "relationDates.status": 1
420
+ });
421
+ var RelationModel = import_mongoose5.default.models.Relation || import_mongoose5.default.model("Relation", RelationTypeSchema);
422
+
423
+ // src/mongoose/global.ts
424
+ var MongooseSchema5 = import_mongoose6.default.Schema;
425
+ var OwnerTypeSchema = new MongooseSchema5(
426
+ {
427
+ email: { required: true, type: String },
428
+ userId: {
429
+ ref: "User",
430
+ required: true,
431
+ type: import_mongoose6.default.Schema.Types.ObjectId
432
+ }
433
+ },
434
+ { _id: false }
435
+ // Prevents Mongoose from creating an additional _id field for subdocuments
436
+ );
437
+ var SocialMediaTypeSchema = new MongooseSchema5(
438
+ {
439
+ link: { required: true, type: String },
440
+ name: { required: true, type: String }
441
+ },
442
+ { _id: false }
443
+ // Prevents Mongoose from creating an additional _id field
444
+ );
445
+ var ResourceImageTypeSchema = new MongooseSchema5(
446
+ {
447
+ source: { required: false, type: String },
448
+ title: { required: false, type: String }
449
+ },
450
+ { _id: false }
451
+ // Prevents Mongoose from creating an additional _id field for subdocuments
452
+ );
453
+ var SubCategorySchema = new MongooseSchema5(
454
+ {
455
+ id: { required: false, type: String },
456
+ items: [
457
+ {
458
+ id: { required: false, type: String },
459
+ name: { required: false, type: String }
460
+ }
461
+ ],
462
+ name: { required: false, type: String }
463
+ },
464
+ { _id: false }
465
+ // Prevents Mongoose from creating an additional _id field for subdocuments
466
+ );
467
+ var CategorySchema = new MongooseSchema5(
468
+ {
469
+ id: { required: true, type: String },
470
+ name: { required: true, type: String },
471
+ subcategories: [SubCategorySchema]
472
+ },
473
+ { _id: false }
474
+ // Prevents Mongoose from creating an additional _id field for subdocuments
475
+ );
476
+ var PosterUsageTypeSchema = new MongooseSchema5(
477
+ {
478
+ count: { default: 0, required: false, type: Number },
479
+ month: { required: false, type: String }
480
+ },
481
+ { _id: false }
482
+ // Prevents Mongoose from creating an additional _id field for subdocuments
483
+ );
484
+ var partnersSchema = new MongooseSchema5(
485
+ {
486
+ email: { required: false, type: String },
487
+ licence: {
488
+ enum: Object.values(import_cluemart_shared4.EnumUserLicence),
489
+ required: false,
490
+ type: String
491
+ },
492
+ resourceId: {
493
+ required: false,
494
+ type: String
495
+ },
496
+ resourceType: {
497
+ enum: Object.values(import_cluemart_shared4.EnumResourceType),
498
+ required: false,
499
+ type: String
500
+ }
501
+ },
502
+ { _id: false }
503
+ // Prevents Mongoose from creating an additional _id field for subdocuments
504
+ );
505
+ var ContactDetailsSchema = new MongooseSchema5(
506
+ {
507
+ email: { required: false, type: String },
508
+ landlinePhone: { required: false, type: String },
509
+ mobilePhone: { required: false, type: String }
510
+ },
511
+ { _id: false }
512
+ // Prevents Mongoose from creating an additional _id field for subdocuments
513
+ );
514
+ var termsAgreementSchema = new MongooseSchema5(
515
+ {
516
+ appBuildNumber: { required: true, type: String },
517
+ appId: { required: true, type: String },
518
+ appVersion: { required: true, type: String },
519
+ brand: { required: true, type: String },
520
+ deviceName: { required: true, type: String },
521
+ installationId: { required: true, type: String },
522
+ manufacturer: { required: true, type: String },
523
+ modelName: { required: true, type: String },
524
+ osName: { required: true, type: String },
525
+ osVersion: { required: true, type: String },
526
+ termVersion: { required: true, type: String },
527
+ timestamp: { required: true, type: String }
528
+ },
529
+ { _id: false }
530
+ );
531
+ var resourceRelationsSchema = new MongooseSchema5(
532
+ {
533
+ relationDates: {
534
+ default: [],
535
+ required: false,
536
+ type: [relationDatesSchema]
537
+ },
538
+ relationId: {
539
+ ref: "Relation",
540
+ required: false,
541
+ type: import_mongoose6.default.Schema.Types.ObjectId
542
+ }
543
+ },
544
+ { _id: false }
545
+ );
546
+ var baseResourceFields = {
547
+ active: { default: false, required: true, type: Boolean },
548
+ adIds: {
549
+ ref: "Ad",
550
+ required: false,
551
+ type: [import_mongoose6.default.Schema.Types.ObjectId]
552
+ },
553
+ contactDetails: ContactDetailsSchema,
554
+ cover: ResourceImageTypeSchema,
555
+ deletedAt: { default: null, required: false, type: Date },
556
+ description: { required: true, type: String },
557
+ images: [ResourceImageTypeSchema],
558
+ logo: ResourceImageTypeSchema,
559
+ name: { required: true, type: String },
560
+ owner: OwnerTypeSchema,
561
+ partners: {
562
+ required: false,
563
+ type: [partnersSchema]
564
+ },
565
+ posterUsage: PosterUsageTypeSchema,
566
+ promoCodes: { required: false, type: [String] },
567
+ region: { required: true, type: String },
568
+ relations: {
569
+ default: [],
570
+ required: false,
571
+ type: [resourceRelationsSchema]
572
+ },
573
+ socialMedia: [SocialMediaTypeSchema],
574
+ termsAgreement: termsAgreementSchema
575
+ };
576
+
577
+ // src/mongoose/Ad.ts
578
+ var MongooseSchema6 = import_mongoose7.default.Schema;
579
+ var schema4 = new MongooseSchema6(
580
+ {
581
+ active: { default: true, type: Boolean },
582
+ adStyle: {
583
+ default: import_cluemart_shared5.EnumAdStyle.BLOOM,
584
+ enum: Object.values(import_cluemart_shared5.EnumAdStyle),
585
+ required: true,
586
+ type: String
587
+ },
588
+ adType: {
589
+ default: import_cluemart_shared5.EnumAdType.SPONSORED,
590
+ enum: Object.values(import_cluemart_shared5.EnumAdType),
591
+ required: true,
592
+ type: String
593
+ },
594
+ // TODO: similar to ViewSchema
595
+ clicks: { default: 0, required: true, type: Number },
596
+ clui: { required: false, type: String },
597
+ end: { required: true, type: Date },
598
+ // TODO: similar to ViewSchema
599
+ impressions: { default: 0, required: true, type: Number },
600
+ resourceCover: { required: true, type: String },
601
+ resourceDescription: { required: true, type: String },
602
+ resourceId: { required: true, type: String },
603
+ resourceLogo: { required: false, type: String },
604
+ resourceName: { required: true, type: String },
605
+ resourceRegion: { required: true, type: String },
606
+ resourceType: {
607
+ enum: Object.values(import_cluemart_shared5.EnumResourceType),
608
+ required: true,
609
+ type: String
610
+ },
611
+ showOn: {
612
+ default: import_cluemart_shared5.EnumAdShowOn.FRONT_PAGE,
613
+ enum: Object.values(import_cluemart_shared5.EnumAdShowOn),
614
+ required: true,
615
+ type: String
616
+ },
617
+ socialMedia: [SocialMediaTypeSchema],
618
+ start: { required: true, type: Date },
619
+ status: {
620
+ default: import_cluemart_shared5.EnumAdStatus.ACTIVE,
621
+ enum: Object.values(import_cluemart_shared5.EnumAdStatus),
622
+ required: true,
623
+ type: String
624
+ },
625
+ targetRegion: { required: false, type: String }
626
+ },
627
+ {
628
+ timestamps: true
629
+ }
630
+ );
631
+ schema4.index({
632
+ end: 1,
633
+ start: 1,
634
+ status: 1
635
+ });
636
+ var AdModel = import_mongoose7.default.models.Ad || import_mongoose7.default.model("Ad", schema4);
637
+
638
+ // src/mongoose/Chat.ts
639
+ var import_cluemart_shared6 = require("@timardex/cluemart-shared");
640
+ var import_mongoose8 = __toESM(require("mongoose"));
641
+ var MongooseSchema7 = import_mongoose8.default.Schema;
642
+ var MessageSchema = new MongooseSchema7(
643
+ {
644
+ content: { required: true, type: String },
645
+ senderAvatar: { required: false, type: String },
646
+ senderId: {
647
+ ref: "User",
648
+ required: true,
649
+ type: import_mongoose8.default.Schema.Types.ObjectId
650
+ },
651
+ senderName: { required: true, type: String }
652
+ },
653
+ { timestamps: true }
654
+ );
655
+ var ParticipantSchema = new MongooseSchema7(
656
+ {
657
+ active: { default: true, required: true, type: Boolean },
658
+ email: { required: true, type: String },
659
+ userId: {
660
+ ref: "User",
661
+ required: true,
662
+ type: import_mongoose8.default.Schema.Types.ObjectId
663
+ }
664
+ },
665
+ { _id: false }
666
+ // Prevents Mongoose from creating an additional _id field for subdocuments
667
+ );
668
+ var ChatSchema = new MongooseSchema7(
669
+ {
670
+ active: { default: true, required: true, type: Boolean },
671
+ chatName: { required: true, type: String },
672
+ chatType: {
673
+ enum: Object.values(import_cluemart_shared6.EnumChatType),
674
+ required: true,
675
+ type: String
676
+ },
677
+ deletedAt: { default: null, required: false, type: Date },
678
+ messages: [MessageSchema],
679
+ participants: [ParticipantSchema],
680
+ resourceInfo: {
681
+ eventId: {
682
+ ref: "Event",
683
+ required: false,
684
+ type: import_mongoose8.default.Schema.Types.ObjectId
685
+ },
686
+ vendorId: {
687
+ ref: "Vendor",
688
+ required: false,
689
+ type: import_mongoose8.default.Schema.Types.ObjectId
690
+ }
691
+ }
692
+ },
693
+ {
694
+ timestamps: true
695
+ }
696
+ );
697
+ var ChatModel = import_mongoose8.default.models.Chat || import_mongoose8.default.model("Chat", ChatSchema);
698
+
699
+ // src/mongoose/ResourceActivity.ts
700
+ var import_cluemart_shared7 = require("@timardex/cluemart-shared");
701
+ var import_mongoose9 = __toESM(require("mongoose"));
702
+ var MongooseSchema8 = import_mongoose9.default.Schema;
703
+ var ActivitySchema = new MongooseSchema8(
704
+ {
705
+ activityType: {
706
+ enum: Object.values(import_cluemart_shared7.EnumActivity),
707
+ required: true,
708
+ type: String
709
+ },
710
+ location: {
711
+ coordinates: {
712
+ required: false,
713
+ type: [Number]
714
+ },
715
+ type: {
716
+ default: "Point",
717
+ enum: ["Point"],
718
+ required: false,
719
+ type: String
720
+ }
721
+ },
722
+ startDate: { required: false, type: String },
723
+ startTime: { required: false, type: String },
724
+ timestamp: { default: Date.now, type: Date },
725
+ userAgent: {
726
+ enum: Object.values(import_cluemart_shared7.EnumOSPlatform),
727
+ required: true,
728
+ type: String
729
+ },
730
+ userId: { required: false, type: String }
731
+ },
732
+ { _id: false }
733
+ );
734
+ var schema5 = new MongooseSchema8(
735
+ {
736
+ activity: { default: [], type: [ActivitySchema] },
737
+ resourceId: { required: true, type: String },
738
+ resourceType: {
739
+ enum: Object.values(import_cluemart_shared7.EnumResourceType),
740
+ required: true,
741
+ type: String
742
+ }
743
+ },
744
+ { timestamps: true }
745
+ );
746
+ schema5.index({ resourceId: 1, resourceType: 1 }, { unique: true });
747
+ schema5.index({ "views.location": "2dsphere" });
748
+ var ResourceActivityModel = import_mongoose9.default.models.ResourceActivity || import_mongoose9.default.model("ResourceActivity", schema5);
749
+
750
+ // src/mongoose/Testers.ts
751
+ var import_cluemart_shared8 = require("@timardex/cluemart-shared");
752
+ var import_mongoose10 = __toESM(require("mongoose"));
753
+ var MongooseSchema9 = import_mongoose10.default.Schema;
754
+ var TesterSchema = new MongooseSchema9(
755
+ {
756
+ active: { default: false, required: true, type: Boolean },
757
+ categories: [CategorySchema],
758
+ companyName: { required: true, type: String },
759
+ email: { required: true, type: String },
760
+ firstName: { required: true, type: String },
761
+ lastName: { required: true, type: String },
762
+ osType: {
763
+ enum: Object.values(import_cluemart_shared8.EnumOSPlatform),
764
+ required: true,
765
+ type: String
766
+ },
767
+ region: { required: true, type: String },
768
+ resourceType: {
769
+ enum: Object.values(import_cluemart_shared8.EnumResourceType),
770
+ required: true,
771
+ type: String
772
+ }
773
+ },
774
+ {
775
+ timestamps: true
776
+ }
777
+ );
778
+ var TesterModel = import_mongoose10.default.models.Tester || import_mongoose10.default.model("Tester", TesterSchema);
779
+
780
+ // src/mongoose/User.ts
781
+ var import_cluemart_shared9 = require("@timardex/cluemart-shared");
782
+ var import_mongoose11 = __toESM(require("mongoose"));
783
+ var MongooseSchema10 = import_mongoose11.default.Schema;
784
+ var userActivityEventSchema = new MongooseSchema10(
785
+ {
786
+ resourceId: {
787
+ ref: "Event",
788
+ required: false,
789
+ type: import_mongoose11.default.Schema.Types.ObjectId
790
+ },
791
+ startDate: { required: false, type: String },
792
+ startTime: { required: false, type: String }
793
+ },
794
+ { _id: false }
795
+ );
796
+ var userActivityFavouritesSchema = new MongooseSchema10(
797
+ {
798
+ events: {
799
+ ref: "Event",
800
+ required: false,
801
+ type: [import_mongoose11.default.Schema.Types.ObjectId]
802
+ },
803
+ vendors: {
804
+ ref: "Vendor",
805
+ required: false,
806
+ type: [import_mongoose11.default.Schema.Types.ObjectId]
807
+ }
808
+ },
809
+ { _id: false }
810
+ );
811
+ var schema6 = new MongooseSchema10(
812
+ {
813
+ active: { default: false, required: true, type: Boolean },
814
+ avatar: ResourceImageTypeSchema,
815
+ deletedAt: { default: null, required: false, type: Date },
816
+ email: { required: true, type: String },
817
+ events: {
818
+ ref: "Event",
819
+ required: false,
820
+ type: [import_mongoose11.default.Schema.Types.ObjectId]
821
+ },
822
+ firstName: { required: true, type: String },
823
+ isTester: { default: false, required: false, type: Boolean },
824
+ lastName: { required: true, type: String },
825
+ licences: {
826
+ enum: Object.values(import_cluemart_shared9.EnumUserLicence),
827
+ required: false,
828
+ type: [String]
829
+ },
830
+ partners: {
831
+ required: false,
832
+ type: [partnersSchema]
833
+ },
834
+ password: { required: true, type: String },
835
+ platform: {
836
+ enum: Object.values(import_cluemart_shared9.EnumOSPlatform),
837
+ required: false,
838
+ type: String
839
+ },
840
+ preferredRegion: {
841
+ required: true,
842
+ type: String
843
+ },
844
+ refreshToken: {
845
+ required: false,
846
+ type: String
847
+ },
848
+ role: {
849
+ default: import_cluemart_shared9.EnumUserRole.CUSTOMER,
850
+ enum: Object.values(import_cluemart_shared9.EnumUserRole),
851
+ required: true,
852
+ type: String
853
+ },
854
+ termsAgreement: termsAgreementSchema,
855
+ userActivity: {
856
+ favourites: {
857
+ default: () => ({ events: [], vendors: [] }),
858
+ type: userActivityFavouritesSchema
859
+ },
860
+ going: {
861
+ events: [userActivityEventSchema]
862
+ },
863
+ interested: {
864
+ events: [userActivityEventSchema]
865
+ },
866
+ present: {
867
+ events: [userActivityEventSchema]
868
+ }
869
+ },
870
+ vendor: {
871
+ ref: "Vendor",
872
+ required: false,
873
+ type: import_mongoose11.default.Schema.Types.ObjectId
874
+ }
875
+ },
876
+ { timestamps: true }
877
+ );
878
+ schema6.index({ "partners.email": 1 });
879
+ var UserModel = import_mongoose11.default.models.User || import_mongoose11.default.model("User", schema6);
880
+
881
+ // src/mongoose/VerificationToken.ts
882
+ var import_mongoose12 = __toESM(require("mongoose"));
883
+ var MongooseSchema11 = import_mongoose12.default.Schema;
884
+ var schema7 = new MongooseSchema11(
885
+ {
886
+ createdAt: {
887
+ default: Date.now,
888
+ expires: 24 * 60 * 60,
889
+ // 24 hours in seconds (MongoDB TTL expects seconds)
890
+ required: true,
891
+ type: Date
892
+ },
893
+ // Token expires after 1 day
894
+ email: { required: true, type: String },
895
+ verificationToken: { required: true, type: String }
896
+ },
897
+ { timestamps: true }
898
+ );
899
+ var VerificationTokenModel = import_mongoose12.default.models.VerificationToken || import_mongoose12.default.model("VerificationToken", schema7);
900
+
901
+ // src/mongoose/vendor/Vendor.ts
902
+ var import_cluemart_shared10 = require("@timardex/cluemart-shared");
903
+ var import_mongoose13 = __toESM(require("mongoose"));
904
+ var MongooseSchema12 = import_mongoose13.default.Schema;
905
+ var MenuTypeSchema = new MongooseSchema12(
906
+ {
907
+ description: { required: false, type: String },
908
+ name: { required: false, type: String },
909
+ price: { required: false, type: Number },
910
+ productGroups: { required: false, type: [String] }
911
+ },
912
+ { _id: false }
913
+ // Prevents Mongoose from creating an additional _id field for subdocuments
914
+ );
915
+ var LocationsSchema = new MongooseSchema12(
916
+ {
917
+ dateTime: {
918
+ endDate: { required: false, type: String },
919
+ endTime: { required: false, type: String },
920
+ startDate: { required: false, type: String },
921
+ startTime: { required: false, type: String }
922
+ },
923
+ description: { required: false, type: String },
924
+ location: {
925
+ city: { required: false, type: String },
926
+ coordinates: {
927
+ required: false,
928
+ type: [Number]
929
+ // [longitude, latitude]
930
+ },
931
+ country: { required: false, type: String },
932
+ fullAddress: { required: false, type: String },
933
+ latitude: { required: false, type: Number },
934
+ longitude: { required: false, type: Number },
935
+ region: { required: false, type: String },
936
+ type: { required: false, type: String }
937
+ // Mongoose GeoJSON type
938
+ }
939
+ },
940
+ { _id: false }
941
+ // Prevents Mongoose from creating an additional _id field for subdocuments
942
+ );
943
+ var schema8 = new MongooseSchema12(
944
+ {
945
+ ...baseResourceFields,
946
+ // Importing base resource fields from global.ts
947
+ availability: {
948
+ corporate: { default: false, required: false, type: Boolean },
949
+ private: { default: false, required: false, type: Boolean },
950
+ school: { default: false, required: false, type: Boolean }
951
+ },
952
+ categories: [CategorySchema],
953
+ locations: [LocationsSchema],
954
+ multiLocation: { required: true, type: Boolean },
955
+ products: [MenuTypeSchema],
956
+ vendorInfoId: {
957
+ ref: "VendorInfo",
958
+ required: false,
959
+ type: import_mongoose13.default.Schema.Types.ObjectId
960
+ },
961
+ vendorType: {
962
+ enum: Object.values(import_cluemart_shared10.EnumVendorType),
963
+ required: true,
964
+ type: String
965
+ }
966
+ },
967
+ { timestamps: true }
968
+ );
969
+ schema8.index({ name: 1 });
970
+ schema8.index({ description: 1 });
971
+ schema8.index({ region: 1 });
972
+ schema8.index({ "categories.name": 1 });
973
+ schema8.index({ "partners.email": 1 });
974
+ var VendorModel = import_mongoose13.default.models.Vendor || import_mongoose13.default.model("Vendor", schema8);
975
+
976
+ // src/mongoose/vendor/VendorInfo.ts
977
+ var import_cluemart_shared11 = require("@timardex/cluemart-shared");
978
+ var import_mongoose14 = __toESM(require("mongoose"));
979
+ var MongooseSchema13 = import_mongoose14.default.Schema;
980
+ var AttributesSchema = new MongooseSchema13(
981
+ {
982
+ details: { required: false, type: String },
983
+ isRequired: { default: false, required: true, type: Boolean }
984
+ },
985
+ { _id: false }
986
+ );
987
+ var schema9 = new MongooseSchema13(
988
+ {
989
+ compliance: {
990
+ foodBeverageLicense: { default: false, required: false, type: Boolean },
991
+ liabilityInsurance: { default: false, required: false, type: Boolean }
992
+ },
993
+ documents: [ResourceImageTypeSchema],
994
+ product: {
995
+ foodFlavors: {
996
+ enum: Object.values(import_cluemart_shared11.EnumFoodFlavor),
997
+ required: true,
998
+ type: [String]
999
+ },
1000
+ packaging: { required: true, type: [String] },
1001
+ priceRange: {
1002
+ max: { required: true, type: Number },
1003
+ min: { required: true, type: Number }
1004
+ },
1005
+ producedIn: { required: true, type: [String] }
1006
+ },
1007
+ requirements: {
1008
+ electricity: AttributesSchema,
1009
+ gazebo: AttributesSchema,
1010
+ table: AttributesSchema
1011
+ },
1012
+ stallInfo: {
1013
+ size: {
1014
+ depth: { required: true, type: Number },
1015
+ width: { required: true, type: Number }
1016
+ }
1017
+ },
1018
+ vendorId: {
1019
+ ref: "Vendor",
1020
+ required: true,
1021
+ type: import_mongoose14.default.Schema.Types.ObjectId
1022
+ }
1023
+ },
1024
+ { timestamps: true }
1025
+ );
1026
+ var VendorInfoModel = import_mongoose14.default.models.VendorInfo || import_mongoose14.default.model("VendorInfo", schema9);
1027
+
1028
+ // src/mongoose/event/Event.ts
1029
+ var import_cluemart_shared12 = require("@timardex/cluemart-shared");
1030
+ var import_mongoose15 = __toESM(require("mongoose"));
1031
+ var MongooseSchema14 = import_mongoose15.default.Schema;
1032
+ var locationsSchema = new MongooseSchema14(
1033
+ {
1034
+ city: { required: true, type: String },
1035
+ coordinates: {
1036
+ required: true,
1037
+ type: [Number]
1038
+ // [longitude, latitude]
1039
+ },
1040
+ country: { required: true, type: String },
1041
+ fullAddress: { required: true, type: String },
1042
+ latitude: { required: true, type: Number },
1043
+ longitude: { required: true, type: Number },
1044
+ region: { required: true, type: String },
1045
+ type: {
1046
+ default: "Point",
1047
+ enum: ["Point"],
1048
+ required: true,
1049
+ type: String
1050
+ }
1051
+ },
1052
+ { _id: false }
1053
+ // Prevents Mongoose from creating an additional _id field for subdocuments
1054
+ );
1055
+ var dateTimeSchema2 = new MongooseSchema14(
1056
+ {
1057
+ endDate: { required: true, type: String },
1058
+ endTime: { required: true, type: String },
1059
+ startDate: { required: true, type: String },
1060
+ startTime: { required: true, type: String }
1061
+ },
1062
+ { _id: false }
1063
+ // Prevents Mongoose from creating an additional _id field for subdocuments
1064
+ );
1065
+ var schema10 = new MongooseSchema14(
1066
+ {
1067
+ ...baseResourceFields,
1068
+ // Importing base resource fields from global.ts
1069
+ dateTime: [dateTimeSchema2],
1070
+ eventInfoId: {
1071
+ ref: "EventInfo",
1072
+ required: false,
1073
+ type: import_mongoose15.default.Schema.Types.ObjectId
1074
+ },
1075
+ eventType: {
1076
+ enum: Object.values(import_cluemart_shared12.EnumEventType),
1077
+ required: true,
1078
+ type: String
1079
+ },
1080
+ location: {
1081
+ required: true,
1082
+ type: locationsSchema
1083
+ },
1084
+ nzbn: { required: true, type: String },
1085
+ provider: { required: false, type: String },
1086
+ rainOrShine: { required: true, type: Boolean },
1087
+ tags: { required: true, type: [String] }
1088
+ },
1089
+ { timestamps: true }
1090
+ );
1091
+ schema10.index({ name: 1 });
1092
+ schema10.index({ description: 1 });
1093
+ schema10.index({ region: 1 });
1094
+ schema10.index({ location: "2dsphere" });
1095
+ schema10.index({ tags: 1 });
1096
+ schema10.index({ "partners.email": 1 });
1097
+ var EventModel = import_mongoose15.default.models.Event || import_mongoose15.default.model("Event", schema10);
1098
+
1099
+ // src/service/updateAdStatus.ts
1100
+ async function updateAdStatuses() {
1101
+ const now = /* @__PURE__ */ new Date();
1102
+ const invalidResult = await AdModel.updateMany(
1103
+ {
1104
+ $or: [
1105
+ { start: { $exists: false } },
1106
+ { end: { $exists: false } },
1107
+ { $expr: { $gt: ["$start", "$end"] } }
1108
+ ]
1109
+ },
1110
+ { $set: { status: import_cluemart_shared13.EnumAdStatus.PAUSED } }
1111
+ );
1112
+ const expiredResult = await AdModel.updateMany(
1113
+ { end: { $lte: now }, status: { $ne: import_cluemart_shared13.EnumAdStatus.EXPIRED } },
1114
+ { $set: { status: import_cluemart_shared13.EnumAdStatus.EXPIRED } }
1115
+ );
1116
+ const activeResult = await AdModel.updateMany(
1117
+ {
1118
+ end: { $gt: now },
1119
+ start: { $lte: now },
1120
+ status: { $ne: import_cluemart_shared13.EnumAdStatus.ACTIVE }
1121
+ },
1122
+ { $set: { status: import_cluemart_shared13.EnumAdStatus.ACTIVE } }
1123
+ );
1124
+ const pausedResult = await AdModel.updateMany(
1125
+ { start: { $gt: now }, status: { $ne: import_cluemart_shared13.EnumAdStatus.PAUSED } },
1126
+ { $set: { status: import_cluemart_shared13.EnumAdStatus.PAUSED } }
1127
+ );
1128
+ console.log(
1129
+ `\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
1130
+ );
1131
+ }
1132
+ // Annotate the CommonJS export names for ESM import in node:
1133
+ 0 && (module.exports = {
1134
+ connectToDatabase,
1135
+ saveNotificationsInDb,
1136
+ sendPushNotifications,
1137
+ updateAdStatuses
1138
+ });
1139
+ //# sourceMappingURL=index.cjs.map