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