@timardex/cluemart-server-shared 2.0.2 → 2.1.1
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/{Affiliate-CMJdECzs.d.mts → Affiliate-B1mxoMeD.d.mts} +3 -0
- package/dist/{Affiliate-VLZdlt5K.d.ts → Affiliate-Dlf_OLIh.d.ts} +3 -0
- package/dist/{chunk-IICIHY26.mjs → chunk-MEEBCSMJ.mjs} +537 -213
- package/dist/chunk-MEEBCSMJ.mjs.map +1 -0
- package/dist/index.cjs +920 -453
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +62 -6
- package/dist/index.d.ts +62 -6
- package/dist/index.mjs +751 -278
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +613 -291
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +47 -4
- package/dist/mongoose/index.d.ts +47 -4
- package/dist/mongoose/index.mjs +15 -1
- package/dist/service/index.cjs +895 -450
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +16 -6
- package/dist/service/index.d.ts +16 -6
- package/dist/service/index.mjs +209 -60
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-IICIHY26.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/mongoose/Ad.ts
|
|
2
2
|
import {
|
|
3
|
+
EnumAdApprovalStatus,
|
|
4
|
+
EnumAdBookingSlotKind,
|
|
5
|
+
EnumAdPaymentStatus,
|
|
3
6
|
EnumAdShowOn,
|
|
4
7
|
EnumAdStatus,
|
|
5
8
|
EnumAdStyle,
|
|
@@ -37,9 +40,30 @@ var schemaAdresource = new MongooseSchema({
|
|
|
37
40
|
var schema = new MongooseSchema(
|
|
38
41
|
{
|
|
39
42
|
active: { default: true, type: Boolean },
|
|
43
|
+
adminManaged: { default: false, type: Boolean },
|
|
44
|
+
approvalStatus: {
|
|
45
|
+
enum: Object.values(EnumAdApprovalStatus),
|
|
46
|
+
required: false,
|
|
47
|
+
type: String
|
|
48
|
+
},
|
|
49
|
+
bookingIds: {
|
|
50
|
+
default: void 0,
|
|
51
|
+
ref: "AdBooking",
|
|
52
|
+
type: [mongoose.Schema.Types.ObjectId]
|
|
53
|
+
},
|
|
54
|
+
bookingKind: {
|
|
55
|
+
enum: Object.values(EnumAdBookingSlotKind),
|
|
56
|
+
required: false,
|
|
57
|
+
type: String
|
|
58
|
+
},
|
|
40
59
|
clicks: { default: 0, required: true, type: Number },
|
|
41
60
|
end: { required: true, type: Date },
|
|
42
61
|
impressions: { default: 0, required: true, type: Number },
|
|
62
|
+
paymentStatus: {
|
|
63
|
+
enum: Object.values(EnumAdPaymentStatus),
|
|
64
|
+
required: false,
|
|
65
|
+
type: String
|
|
66
|
+
},
|
|
43
67
|
resource: { required: true, type: schemaAdresource },
|
|
44
68
|
showOn: {
|
|
45
69
|
default: [EnumAdShowOn.FRONT_PAGE],
|
|
@@ -71,8 +95,276 @@ schema.index({
|
|
|
71
95
|
// eslint-disable-next-line sort-keys
|
|
72
96
|
start: -1
|
|
73
97
|
});
|
|
98
|
+
schema.index(
|
|
99
|
+
{ bookingIds: 1 },
|
|
100
|
+
{
|
|
101
|
+
partialFilterExpression: { bookingIds: { $exists: true } },
|
|
102
|
+
unique: true
|
|
103
|
+
}
|
|
104
|
+
);
|
|
74
105
|
var AdModel = mongoose.models.Ad || mongoose.model("Ad", schema);
|
|
75
106
|
|
|
107
|
+
// src/mongoose/AdBillingCatalog.ts
|
|
108
|
+
import mongoose2 from "mongoose";
|
|
109
|
+
var AD_BILLING_CATALOG_COLLECTION_NAME = "adBillingCatalog";
|
|
110
|
+
var schema2 = new mongoose2.Schema(
|
|
111
|
+
{
|
|
112
|
+
active: { default: true, required: true, type: Boolean },
|
|
113
|
+
currency: {
|
|
114
|
+
default: "nzd",
|
|
115
|
+
enum: ["nzd"],
|
|
116
|
+
immutable: true,
|
|
117
|
+
required: true,
|
|
118
|
+
type: String
|
|
119
|
+
},
|
|
120
|
+
key: {
|
|
121
|
+
enum: ["front_page_day", "market_search_day"],
|
|
122
|
+
immutable: true,
|
|
123
|
+
required: true,
|
|
124
|
+
type: String,
|
|
125
|
+
unique: true
|
|
126
|
+
},
|
|
127
|
+
revision: { default: 1, min: 1, required: true, type: Number },
|
|
128
|
+
unitAmount: {
|
|
129
|
+
min: 1,
|
|
130
|
+
required: true,
|
|
131
|
+
type: Number,
|
|
132
|
+
validate: {
|
|
133
|
+
message: "Daily ad price must be a positive integer amount of cents.",
|
|
134
|
+
validator: Number.isInteger
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
{ collection: AD_BILLING_CATALOG_COLLECTION_NAME, timestamps: true }
|
|
139
|
+
);
|
|
140
|
+
var AdBillingCatalogModel = mongoose2.models.AdBillingCatalog || mongoose2.model(
|
|
141
|
+
"AdBillingCatalog",
|
|
142
|
+
schema2,
|
|
143
|
+
AD_BILLING_CATALOG_COLLECTION_NAME
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// src/mongoose/AdBooking.ts
|
|
147
|
+
import {
|
|
148
|
+
EnumAdApprovalStatus as EnumAdApprovalStatus2,
|
|
149
|
+
EnumAdBookingSlotKind as EnumAdBookingSlotKind2,
|
|
150
|
+
EnumAdBookingState,
|
|
151
|
+
EnumAdEntitlementSource,
|
|
152
|
+
EnumAdShowOn as EnumAdShowOn2
|
|
153
|
+
} from "@timardex/cluemart-shared";
|
|
154
|
+
import mongoose3 from "mongoose";
|
|
155
|
+
var liveStates = [
|
|
156
|
+
EnumAdBookingState.HELD,
|
|
157
|
+
EnumAdBookingState.PENDING_APPROVAL,
|
|
158
|
+
EnumAdBookingState.APPROVED
|
|
159
|
+
];
|
|
160
|
+
var placementValues = [EnumAdShowOn2.FRONT_PAGE, EnumAdShowOn2.MARKET_SEARCH];
|
|
161
|
+
var schema3 = new mongoose3.Schema(
|
|
162
|
+
{
|
|
163
|
+
adId: { default: null, ref: "Ad", type: String },
|
|
164
|
+
approvalStatus: {
|
|
165
|
+
default: EnumAdApprovalStatus2.PENDING,
|
|
166
|
+
enum: Object.values(EnumAdApprovalStatus2),
|
|
167
|
+
required: true,
|
|
168
|
+
type: String
|
|
169
|
+
},
|
|
170
|
+
checkoutAttemptId: { default: null, type: String },
|
|
171
|
+
currency: { default: null, lowercase: true, type: String },
|
|
172
|
+
dayKey: {
|
|
173
|
+
immutable: true,
|
|
174
|
+
match: /^\d{4}-\d{2}-\d{2}$/,
|
|
175
|
+
required: true,
|
|
176
|
+
type: String
|
|
177
|
+
},
|
|
178
|
+
entitlementClaimKey: { default: null, type: String },
|
|
179
|
+
entitlementSource: {
|
|
180
|
+
default: null,
|
|
181
|
+
enum: Object.values(EnumAdEntitlementSource),
|
|
182
|
+
type: String
|
|
183
|
+
},
|
|
184
|
+
expiresAt: { default: null, type: Date },
|
|
185
|
+
placement: {
|
|
186
|
+
enum: placementValues,
|
|
187
|
+
immutable: true,
|
|
188
|
+
required: true,
|
|
189
|
+
type: String
|
|
190
|
+
},
|
|
191
|
+
purchaseKey: { default: null, immutable: true, type: String },
|
|
192
|
+
region: {
|
|
193
|
+
immutable: true,
|
|
194
|
+
lowercase: true,
|
|
195
|
+
required: true,
|
|
196
|
+
trim: true,
|
|
197
|
+
type: String
|
|
198
|
+
},
|
|
199
|
+
resource: { required: true, type: schemaAdresource },
|
|
200
|
+
slotKind: {
|
|
201
|
+
enum: Object.values(EnumAdBookingSlotKind2),
|
|
202
|
+
immutable: true,
|
|
203
|
+
required: true,
|
|
204
|
+
type: String
|
|
205
|
+
},
|
|
206
|
+
slotNumber: { immutable: true, min: 1, required: true, type: Number },
|
|
207
|
+
state: {
|
|
208
|
+
default: EnumAdBookingState.HELD,
|
|
209
|
+
enum: Object.values(EnumAdBookingState),
|
|
210
|
+
required: true,
|
|
211
|
+
type: String
|
|
212
|
+
},
|
|
213
|
+
stripeCheckoutSessionId: { default: null, type: String },
|
|
214
|
+
stripePaymentIntentId: { default: null, type: String },
|
|
215
|
+
unitAmount: { default: null, min: 1, type: Number },
|
|
216
|
+
userId: { immutable: true, ref: "User", required: true, type: String }
|
|
217
|
+
},
|
|
218
|
+
{ timestamps: true }
|
|
219
|
+
);
|
|
220
|
+
schema3.pre(
|
|
221
|
+
"validate",
|
|
222
|
+
function validateSlot() {
|
|
223
|
+
if (!Number.isInteger(this.slotNumber)) {
|
|
224
|
+
this.invalidate("slotNumber", "Ad booking slot must be an integer.");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const maximum = this.slotKind === EnumAdBookingSlotKind2.PAID ? 30 : 7;
|
|
228
|
+
if (this.slotNumber < 1 || this.slotNumber > maximum) {
|
|
229
|
+
this.invalidate(
|
|
230
|
+
"slotNumber",
|
|
231
|
+
`Ad booking slot must be between 1 and ${maximum}.`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
if (this.slotKind === EnumAdBookingSlotKind2.PAID && this.state !== EnumAdBookingState.HELD && this.state !== EnumAdBookingState.FAILED && this.state !== EnumAdBookingState.CANCELLED && (!this.unitAmount || !this.currency)) {
|
|
235
|
+
this.invalidate(
|
|
236
|
+
"unitAmount",
|
|
237
|
+
"Paid ad booking must retain its checkout price."
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
schema3.index(
|
|
243
|
+
{ region: 1, placement: 1, dayKey: 1, slotKind: 1, slotNumber: 1 },
|
|
244
|
+
{ unique: true, partialFilterExpression: { state: { $in: liveStates } } }
|
|
245
|
+
);
|
|
246
|
+
schema3.index({ userId: 1, dayKey: -1 });
|
|
247
|
+
schema3.index(
|
|
248
|
+
{ checkoutAttemptId: 1 },
|
|
249
|
+
{
|
|
250
|
+
partialFilterExpression: { checkoutAttemptId: { $type: "string" } },
|
|
251
|
+
unique: true
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
schema3.index(
|
|
255
|
+
{ purchaseKey: 1 },
|
|
256
|
+
{
|
|
257
|
+
partialFilterExpression: {
|
|
258
|
+
purchaseKey: { $type: "string" },
|
|
259
|
+
state: { $in: liveStates }
|
|
260
|
+
},
|
|
261
|
+
unique: true
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
schema3.index(
|
|
265
|
+
{ entitlementClaimKey: 1 },
|
|
266
|
+
{
|
|
267
|
+
partialFilterExpression: {
|
|
268
|
+
entitlementClaimKey: { $type: "string" },
|
|
269
|
+
state: { $in: liveStates }
|
|
270
|
+
},
|
|
271
|
+
unique: true
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
schema3.index(
|
|
275
|
+
{ adId: 1, region: 1, placement: 1, dayKey: 1 },
|
|
276
|
+
{
|
|
277
|
+
partialFilterExpression: {
|
|
278
|
+
entitlementSource: EnumAdEntitlementSource.ADMIN,
|
|
279
|
+
state: { $in: liveStates }
|
|
280
|
+
},
|
|
281
|
+
unique: true
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
schema3.index(
|
|
285
|
+
{ stripeCheckoutSessionId: 1 },
|
|
286
|
+
{
|
|
287
|
+
partialFilterExpression: { stripeCheckoutSessionId: { $type: "string" } },
|
|
288
|
+
unique: true
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
var AdBookingModel = mongoose3.models.AdBooking || mongoose3.model("AdBooking", schema3);
|
|
292
|
+
|
|
293
|
+
// src/mongoose/AdImpression.ts
|
|
294
|
+
import { EnumAdShowOn as EnumAdShowOn3 } from "@timardex/cluemart-shared";
|
|
295
|
+
import mongoose4 from "mongoose";
|
|
296
|
+
var schema4 = new mongoose4.Schema(
|
|
297
|
+
{
|
|
298
|
+
_id: { required: true, type: String },
|
|
299
|
+
adId: { required: true, type: String },
|
|
300
|
+
dayKey: { match: /^\d{4}-\d{2}-\d{2}$/, required: true, type: String },
|
|
301
|
+
placement: {
|
|
302
|
+
enum: [EnumAdShowOn3.FRONT_PAGE, EnumAdShowOn3.MARKET_SEARCH],
|
|
303
|
+
required: true,
|
|
304
|
+
type: String
|
|
305
|
+
},
|
|
306
|
+
recordedAt: { default: Date.now, required: true, type: Date },
|
|
307
|
+
viewerSlotKey: { required: true, type: String }
|
|
308
|
+
},
|
|
309
|
+
{ collection: "adImpressions" }
|
|
310
|
+
);
|
|
311
|
+
schema4.index({ adId: 1, recordedAt: 1 });
|
|
312
|
+
schema4.index({ adId: 1, placement: 1, viewerSlotKey: 1 }, { unique: true });
|
|
313
|
+
schema4.index({ recordedAt: 1 }, { expireAfterSeconds: 7 * 24 * 60 * 60 });
|
|
314
|
+
schema4.index({ dayKey: 1, placement: 1, adId: 1 });
|
|
315
|
+
var AdImpressionModel = mongoose4.models.AdImpression || mongoose4.model("AdImpression", schema4, "adImpressions");
|
|
316
|
+
|
|
317
|
+
// src/mongoose/AdSettings.ts
|
|
318
|
+
import mongoose5 from "mongoose";
|
|
319
|
+
var DEFAULT_AD_SETTINGS = {
|
|
320
|
+
_id: "default",
|
|
321
|
+
approvalRequired: true,
|
|
322
|
+
minAppearancesPerHour: 12,
|
|
323
|
+
paidSlotsPerPlacement: 30,
|
|
324
|
+
reservedSlotsPerPlacement: 7,
|
|
325
|
+
rotationSeconds: 8
|
|
326
|
+
};
|
|
327
|
+
var schema5 = new mongoose5.Schema(
|
|
328
|
+
{
|
|
329
|
+
_id: { default: "default", enum: ["default"], type: String },
|
|
330
|
+
approvalRequired: { default: true, required: true, type: Boolean },
|
|
331
|
+
minAppearancesPerHour: {
|
|
332
|
+
default: 12,
|
|
333
|
+
min: 1,
|
|
334
|
+
required: true,
|
|
335
|
+
type: Number,
|
|
336
|
+
validate: {
|
|
337
|
+
message: "Minimum appearances per hour must be a whole number.",
|
|
338
|
+
validator: Number.isInteger
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
paidSlotsPerPlacement: {
|
|
342
|
+
default: 30,
|
|
343
|
+
enum: [30],
|
|
344
|
+
immutable: true,
|
|
345
|
+
type: Number
|
|
346
|
+
},
|
|
347
|
+
reservedSlotsPerPlacement: {
|
|
348
|
+
default: 7,
|
|
349
|
+
enum: [7],
|
|
350
|
+
immutable: true,
|
|
351
|
+
type: Number
|
|
352
|
+
},
|
|
353
|
+
rotationSeconds: { default: 8, enum: [8], immutable: true, type: Number }
|
|
354
|
+
},
|
|
355
|
+
{ collection: "adSettings", timestamps: true }
|
|
356
|
+
);
|
|
357
|
+
schema5.pre("validate", function validateRotationCapacity() {
|
|
358
|
+
const availableRotationsPerHour = 3600 / this.rotationSeconds;
|
|
359
|
+
if (this.minAppearancesPerHour * (this.paidSlotsPerPlacement + this.reservedSlotsPerPlacement) > availableRotationsPerHour) {
|
|
360
|
+
this.invalidate(
|
|
361
|
+
"minAppearancesPerHour",
|
|
362
|
+
"The configured minimum exceeds the available rotation slots."
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
var AdSettingsModel = mongoose5.models.AdSettings || mongoose5.model("AdSettings", schema5, "adSettings");
|
|
367
|
+
|
|
76
368
|
// src/mongoose/BillingCatalog.ts
|
|
77
369
|
import {
|
|
78
370
|
BILLING_CATALOG_CURRENCY,
|
|
@@ -83,8 +375,8 @@ import {
|
|
|
83
375
|
EnumUserLicence,
|
|
84
376
|
INITIAL_BILLING_CATALOG
|
|
85
377
|
} from "@timardex/cluemart-shared";
|
|
86
|
-
import
|
|
87
|
-
var MongooseSchema2 =
|
|
378
|
+
import mongoose6 from "mongoose";
|
|
379
|
+
var MongooseSchema2 = mongoose6.Schema;
|
|
88
380
|
var BILLING_CATALOG_COLLECTION_NAME = "billingCatalog";
|
|
89
381
|
var paidVendorLicences = [
|
|
90
382
|
EnumUserLicence.PRO_VENDOR,
|
|
@@ -131,7 +423,7 @@ var priceHistorySchema = new MongooseSchema2(
|
|
|
131
423
|
default: null,
|
|
132
424
|
ref: "User",
|
|
133
425
|
required: false,
|
|
134
|
-
type:
|
|
426
|
+
type: mongoose6.Schema.Types.ObjectId
|
|
135
427
|
},
|
|
136
428
|
currency: currencyField,
|
|
137
429
|
effectiveFrom: { required: true, type: Date },
|
|
@@ -142,7 +434,7 @@ var priceHistorySchema = new MongooseSchema2(
|
|
|
142
434
|
},
|
|
143
435
|
{ _id: false }
|
|
144
436
|
);
|
|
145
|
-
var
|
|
437
|
+
var schema6 = new MongooseSchema2(
|
|
146
438
|
{
|
|
147
439
|
active: { default: true, required: true, type: Boolean },
|
|
148
440
|
billingPeriod: {
|
|
@@ -198,7 +490,7 @@ var schema2 = new MongooseSchema2(
|
|
|
198
490
|
default: null,
|
|
199
491
|
ref: "User",
|
|
200
492
|
required: false,
|
|
201
|
-
type:
|
|
493
|
+
type: mongoose6.Schema.Types.ObjectId
|
|
202
494
|
}
|
|
203
495
|
},
|
|
204
496
|
{
|
|
@@ -207,7 +499,7 @@ var schema2 = new MongooseSchema2(
|
|
|
207
499
|
timestamps: true
|
|
208
500
|
}
|
|
209
501
|
);
|
|
210
|
-
|
|
502
|
+
schema6.pre("validate", function validateDefinition() {
|
|
211
503
|
if (!billingCatalogDefinitionMatches(this)) {
|
|
212
504
|
this.invalidate(
|
|
213
505
|
"key",
|
|
@@ -215,18 +507,18 @@ schema2.pre("validate", function validateDefinition() {
|
|
|
215
507
|
);
|
|
216
508
|
}
|
|
217
509
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
510
|
+
schema6.index({ billingPeriod: 1, licenceType: 1 }, { unique: true });
|
|
511
|
+
schema6.index({ active: 1, licenceType: 1 });
|
|
512
|
+
schema6.index(
|
|
221
513
|
{ stripePriceId: 1 },
|
|
222
514
|
{
|
|
223
515
|
partialFilterExpression: { stripePriceId: { $type: "string" } },
|
|
224
516
|
unique: true
|
|
225
517
|
}
|
|
226
518
|
);
|
|
227
|
-
var BillingCatalogModel =
|
|
519
|
+
var BillingCatalogModel = mongoose6.models.BillingCatalogEntry || mongoose6.model(
|
|
228
520
|
"BillingCatalogEntry",
|
|
229
|
-
|
|
521
|
+
schema6,
|
|
230
522
|
BILLING_CATALOG_COLLECTION_NAME
|
|
231
523
|
);
|
|
232
524
|
function buildInitialBillingCatalogEntries(now = /* @__PURE__ */ new Date()) {
|
|
@@ -254,15 +546,15 @@ function getBillingCatalogDefinition(key) {
|
|
|
254
546
|
import {
|
|
255
547
|
EnumChatType
|
|
256
548
|
} from "@timardex/cluemart-shared";
|
|
257
|
-
import
|
|
258
|
-
var MongooseSchema3 =
|
|
549
|
+
import mongoose7 from "mongoose";
|
|
550
|
+
var MongooseSchema3 = mongoose7.Schema;
|
|
259
551
|
var MessageReplyPreviewSchema = new MongooseSchema3(
|
|
260
552
|
{
|
|
261
553
|
contentPreview: { required: true, type: String },
|
|
262
554
|
senderId: {
|
|
263
555
|
ref: "User",
|
|
264
556
|
required: true,
|
|
265
|
-
type:
|
|
557
|
+
type: mongoose7.Schema.Types.ObjectId
|
|
266
558
|
},
|
|
267
559
|
senderName: { required: true, type: String }
|
|
268
560
|
},
|
|
@@ -274,7 +566,7 @@ var MessageReactionSchema = new MongooseSchema3(
|
|
|
274
566
|
userId: {
|
|
275
567
|
ref: "User",
|
|
276
568
|
required: true,
|
|
277
|
-
type:
|
|
569
|
+
type: mongoose7.Schema.Types.ObjectId
|
|
278
570
|
}
|
|
279
571
|
},
|
|
280
572
|
{ _id: false }
|
|
@@ -285,7 +577,7 @@ var MessageSeenSchema = new MongooseSchema3(
|
|
|
285
577
|
userId: {
|
|
286
578
|
ref: "User",
|
|
287
579
|
required: true,
|
|
288
|
-
type:
|
|
580
|
+
type: mongoose7.Schema.Types.ObjectId
|
|
289
581
|
}
|
|
290
582
|
},
|
|
291
583
|
{ _id: false }
|
|
@@ -301,13 +593,13 @@ var MessageSchema = new MongooseSchema3(
|
|
|
301
593
|
replyToMessageId: {
|
|
302
594
|
ref: "Chat.messages",
|
|
303
595
|
required: false,
|
|
304
|
-
type:
|
|
596
|
+
type: mongoose7.Schema.Types.ObjectId
|
|
305
597
|
},
|
|
306
598
|
seenBy: { default: [], required: false, type: [MessageSeenSchema] },
|
|
307
599
|
senderId: {
|
|
308
600
|
ref: "User",
|
|
309
601
|
required: true,
|
|
310
|
-
type:
|
|
602
|
+
type: mongoose7.Schema.Types.ObjectId
|
|
311
603
|
}
|
|
312
604
|
},
|
|
313
605
|
{ timestamps: true }
|
|
@@ -320,7 +612,7 @@ var ParticipantSchema = new MongooseSchema3(
|
|
|
320
612
|
userId: {
|
|
321
613
|
ref: "User",
|
|
322
614
|
required: true,
|
|
323
|
-
type:
|
|
615
|
+
type: mongoose7.Schema.Types.ObjectId
|
|
324
616
|
},
|
|
325
617
|
userName: { required: true, type: String }
|
|
326
618
|
},
|
|
@@ -351,14 +643,14 @@ ChatSchema.index({
|
|
|
351
643
|
"participants.userId": 1,
|
|
352
644
|
updatedAt: -1
|
|
353
645
|
});
|
|
354
|
-
var ChatModel =
|
|
646
|
+
var ChatModel = mongoose7.models.Chat || mongoose7.model("Chat", ChatSchema);
|
|
355
647
|
|
|
356
648
|
// src/mongoose/chat/ChatReport.ts
|
|
357
649
|
import {
|
|
358
650
|
EnumChatReportReason
|
|
359
651
|
} from "@timardex/cluemart-shared";
|
|
360
|
-
import
|
|
361
|
-
var MongooseSchema4 =
|
|
652
|
+
import mongoose8 from "mongoose";
|
|
653
|
+
var MongooseSchema4 = mongoose8.Schema;
|
|
362
654
|
var ReasonSchema = new MongooseSchema4(
|
|
363
655
|
{
|
|
364
656
|
details: { default: null, required: false, type: String },
|
|
@@ -375,18 +667,18 @@ var ChatReportSchema = new MongooseSchema4(
|
|
|
375
667
|
chatId: {
|
|
376
668
|
ref: "Chat",
|
|
377
669
|
required: true,
|
|
378
|
-
type:
|
|
670
|
+
type: mongoose8.Schema.Types.ObjectId
|
|
379
671
|
},
|
|
380
672
|
reason: { required: true, type: ReasonSchema },
|
|
381
673
|
reportedUserId: {
|
|
382
674
|
ref: "User",
|
|
383
675
|
required: true,
|
|
384
|
-
type:
|
|
676
|
+
type: mongoose8.Schema.Types.ObjectId
|
|
385
677
|
},
|
|
386
678
|
reporterUserId: {
|
|
387
679
|
ref: "User",
|
|
388
680
|
required: true,
|
|
389
|
-
type:
|
|
681
|
+
type: mongoose8.Schema.Types.ObjectId
|
|
390
682
|
},
|
|
391
683
|
resolved: { default: false, required: true, type: Boolean }
|
|
392
684
|
},
|
|
@@ -394,7 +686,7 @@ var ChatReportSchema = new MongooseSchema4(
|
|
|
394
686
|
);
|
|
395
687
|
ChatReportSchema.index({ chatId: 1, reportedUserId: 1 });
|
|
396
688
|
ChatReportSchema.index({ createdAt: -1, reporterUserId: 1 });
|
|
397
|
-
var ChatReportModel =
|
|
689
|
+
var ChatReportModel = mongoose8.models.ChatReport || mongoose8.model("ChatReport", ChatReportSchema);
|
|
398
690
|
|
|
399
691
|
// src/mongoose/global.ts
|
|
400
692
|
import {
|
|
@@ -402,7 +694,7 @@ import {
|
|
|
402
694
|
EnumPostType,
|
|
403
695
|
EnumUserLicence as EnumUserLicence2
|
|
404
696
|
} from "@timardex/cluemart-shared";
|
|
405
|
-
import
|
|
697
|
+
import mongoose11 from "mongoose";
|
|
406
698
|
|
|
407
699
|
// src/mongoose/Relation.ts
|
|
408
700
|
import {
|
|
@@ -411,15 +703,15 @@ import {
|
|
|
411
703
|
EnumRelationResource,
|
|
412
704
|
EnumResourceType as EnumResourceType2
|
|
413
705
|
} from "@timardex/cluemart-shared";
|
|
414
|
-
import
|
|
706
|
+
import mongoose10 from "mongoose";
|
|
415
707
|
|
|
416
708
|
// src/mongoose/event/EventInfo.ts
|
|
417
709
|
import {
|
|
418
710
|
EnumEventDateStatus,
|
|
419
711
|
EnumPaymentMethod
|
|
420
712
|
} from "@timardex/cluemart-shared";
|
|
421
|
-
import
|
|
422
|
-
var MongooseSchema5 =
|
|
713
|
+
import mongoose9 from "mongoose";
|
|
714
|
+
var MongooseSchema5 = mongoose9.Schema;
|
|
423
715
|
var StallTypeSchema = new MongooseSchema5(
|
|
424
716
|
{
|
|
425
717
|
label: { required: false, type: String },
|
|
@@ -480,7 +772,7 @@ var refundPolicySchema = new MongooseSchema5(
|
|
|
480
772
|
},
|
|
481
773
|
{ _id: false }
|
|
482
774
|
);
|
|
483
|
-
var
|
|
775
|
+
var schema7 = new MongooseSchema5(
|
|
484
776
|
{
|
|
485
777
|
active: { default: true, type: Boolean },
|
|
486
778
|
applicationDeadlineHours: { required: true, type: Number },
|
|
@@ -488,7 +780,7 @@ var schema3 = new MongooseSchema5(
|
|
|
488
780
|
eventId: {
|
|
489
781
|
ref: "Event",
|
|
490
782
|
required: true,
|
|
491
|
-
type:
|
|
783
|
+
type: mongoose9.Schema.Types.ObjectId
|
|
492
784
|
},
|
|
493
785
|
packInTime: { required: true, type: Number },
|
|
494
786
|
paymentDueHours: { required: true, type: Number },
|
|
@@ -498,11 +790,11 @@ var schema3 = new MongooseSchema5(
|
|
|
498
790
|
},
|
|
499
791
|
{ timestamps: true }
|
|
500
792
|
);
|
|
501
|
-
|
|
502
|
-
var EventInfoModel =
|
|
793
|
+
schema7.index({ eventId: 1 });
|
|
794
|
+
var EventInfoModel = mongoose9.models.EventInfo || mongoose9.model("EventInfo", schema7);
|
|
503
795
|
|
|
504
796
|
// src/mongoose/Relation.ts
|
|
505
|
-
var MongooseSchema6 =
|
|
797
|
+
var MongooseSchema6 = mongoose10.Schema;
|
|
506
798
|
var relationDateTimeSchema = new MongooseSchema6(
|
|
507
799
|
{
|
|
508
800
|
dateStatus: {
|
|
@@ -543,13 +835,13 @@ var RelationTypeSchema = new MongooseSchema6(
|
|
|
543
835
|
chatId: {
|
|
544
836
|
ref: "Chat",
|
|
545
837
|
required: true,
|
|
546
|
-
type:
|
|
838
|
+
type: mongoose10.Schema.Types.ObjectId
|
|
547
839
|
},
|
|
548
840
|
deletedAt: { default: null, required: false, type: Date },
|
|
549
841
|
eventId: {
|
|
550
842
|
ref: "Event",
|
|
551
843
|
required: true,
|
|
552
|
-
type:
|
|
844
|
+
type: mongoose10.Schema.Types.ObjectId
|
|
553
845
|
},
|
|
554
846
|
lastUpdateBy: {
|
|
555
847
|
enum: Object.values(EnumResourceType2),
|
|
@@ -565,7 +857,7 @@ var RelationTypeSchema = new MongooseSchema6(
|
|
|
565
857
|
vendorId: {
|
|
566
858
|
ref: "Vendor",
|
|
567
859
|
required: true,
|
|
568
|
-
type:
|
|
860
|
+
type: mongoose10.Schema.Types.ObjectId
|
|
569
861
|
}
|
|
570
862
|
},
|
|
571
863
|
{ timestamps: true }
|
|
@@ -577,17 +869,17 @@ RelationTypeSchema.index({
|
|
|
577
869
|
"relationDates.status": 1,
|
|
578
870
|
vendorId: 1
|
|
579
871
|
});
|
|
580
|
-
var RelationModel =
|
|
872
|
+
var RelationModel = mongoose10.models.Relation || mongoose10.model("Relation", RelationTypeSchema);
|
|
581
873
|
|
|
582
874
|
// src/mongoose/global.ts
|
|
583
|
-
var MongooseSchema7 =
|
|
875
|
+
var MongooseSchema7 = mongoose11.Schema;
|
|
584
876
|
var OwnerTypeSchema = new MongooseSchema7(
|
|
585
877
|
{
|
|
586
878
|
email: { required: true, type: String },
|
|
587
879
|
userId: {
|
|
588
880
|
ref: "User",
|
|
589
881
|
required: true,
|
|
590
|
-
type:
|
|
882
|
+
type: mongoose11.Schema.Types.ObjectId
|
|
591
883
|
}
|
|
592
884
|
},
|
|
593
885
|
{ _id: false }
|
|
@@ -694,7 +986,7 @@ var resourceRelationsSchema = new MongooseSchema7(
|
|
|
694
986
|
relationId: {
|
|
695
987
|
ref: "Relation",
|
|
696
988
|
required: false,
|
|
697
|
-
type:
|
|
989
|
+
type: mongoose11.Schema.Types.ObjectId
|
|
698
990
|
}
|
|
699
991
|
},
|
|
700
992
|
{ _id: false }
|
|
@@ -745,7 +1037,7 @@ var relatedPostSchema = new MongooseSchema7(
|
|
|
745
1037
|
postId: {
|
|
746
1038
|
ref: "Post",
|
|
747
1039
|
required: true,
|
|
748
|
-
type:
|
|
1040
|
+
type: mongoose11.Schema.Types.ObjectId
|
|
749
1041
|
},
|
|
750
1042
|
postSlug: { required: true, type: String },
|
|
751
1043
|
postType: {
|
|
@@ -770,7 +1062,7 @@ var baseResourceFields = {
|
|
|
770
1062
|
adIds: {
|
|
771
1063
|
ref: "Ad",
|
|
772
1064
|
required: false,
|
|
773
|
-
type: [
|
|
1065
|
+
type: [mongoose11.Schema.Types.ObjectId]
|
|
774
1066
|
},
|
|
775
1067
|
approvedAt: { default: null, required: false, type: Date },
|
|
776
1068
|
contactDetails: { required: false, type: ContactDetailsSchema },
|
|
@@ -803,7 +1095,7 @@ var baseResourceFields = {
|
|
|
803
1095
|
import {
|
|
804
1096
|
EnumEventType
|
|
805
1097
|
} from "@timardex/cluemart-shared";
|
|
806
|
-
import
|
|
1098
|
+
import mongoose12 from "mongoose";
|
|
807
1099
|
|
|
808
1100
|
// src/mongoose/searchNamePlugin.ts
|
|
809
1101
|
function deriveSearchName(name) {
|
|
@@ -849,15 +1141,15 @@ function syncSearchNameInUpdate(update) {
|
|
|
849
1141
|
}
|
|
850
1142
|
return null;
|
|
851
1143
|
}
|
|
852
|
-
function searchNamePlugin(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1144
|
+
function searchNamePlugin(schema24) {
|
|
1145
|
+
schema24.add({ searchName: { default: "", required: false, type: String } });
|
|
1146
|
+
schema24.index({ searchName: 1 });
|
|
1147
|
+
schema24.pre("save", function syncSearchNameOnSave(next) {
|
|
856
1148
|
const doc = this;
|
|
857
1149
|
doc.searchName = deriveSearchName(doc.name);
|
|
858
1150
|
next();
|
|
859
1151
|
});
|
|
860
|
-
|
|
1152
|
+
schema24.pre("insertMany", function syncSearchNameOnInsertMany(next, docs) {
|
|
861
1153
|
const list = Array.isArray(docs) ? docs : [docs];
|
|
862
1154
|
for (const doc of list) {
|
|
863
1155
|
if (doc && typeof doc.name === "string") {
|
|
@@ -866,7 +1158,7 @@ function searchNamePlugin(schema20) {
|
|
|
866
1158
|
}
|
|
867
1159
|
next();
|
|
868
1160
|
});
|
|
869
|
-
|
|
1161
|
+
schema24.pre("bulkWrite", function syncSearchNameOnBulkWrite(next, ops) {
|
|
870
1162
|
for (const op of ops) {
|
|
871
1163
|
const doc = op.insertOne?.document ?? op.replaceOne?.replacement;
|
|
872
1164
|
if (doc && typeof doc.name === "string") {
|
|
@@ -892,14 +1184,14 @@ function searchNamePlugin(schema20) {
|
|
|
892
1184
|
}
|
|
893
1185
|
next();
|
|
894
1186
|
};
|
|
895
|
-
|
|
1187
|
+
schema24.pre(
|
|
896
1188
|
["findOneAndUpdate", "updateOne", "updateMany"],
|
|
897
1189
|
syncSearchNameOnUpdate
|
|
898
1190
|
);
|
|
899
1191
|
}
|
|
900
1192
|
|
|
901
1193
|
// src/mongoose/GoogleImportedMarket.ts
|
|
902
|
-
var MongooseSchema8 =
|
|
1194
|
+
var MongooseSchema8 = mongoose12.Schema;
|
|
903
1195
|
var addressComponentSchema = new MongooseSchema8(
|
|
904
1196
|
{
|
|
905
1197
|
longName: { required: false, type: String },
|
|
@@ -908,7 +1200,7 @@ var addressComponentSchema = new MongooseSchema8(
|
|
|
908
1200
|
},
|
|
909
1201
|
{ _id: false }
|
|
910
1202
|
);
|
|
911
|
-
var
|
|
1203
|
+
var schema8 = new MongooseSchema8(
|
|
912
1204
|
{
|
|
913
1205
|
active: { default: false, required: true, type: Boolean },
|
|
914
1206
|
address: { required: true, type: String },
|
|
@@ -920,7 +1212,7 @@ var schema4 = new MongooseSchema8(
|
|
|
920
1212
|
claimedByUserId: {
|
|
921
1213
|
ref: "User",
|
|
922
1214
|
required: false,
|
|
923
|
-
type:
|
|
1215
|
+
type: mongoose12.Schema.Types.ObjectId
|
|
924
1216
|
},
|
|
925
1217
|
cover: {
|
|
926
1218
|
required: false,
|
|
@@ -932,7 +1224,7 @@ var schema4 = new MongooseSchema8(
|
|
|
932
1224
|
eventId: {
|
|
933
1225
|
ref: "Event",
|
|
934
1226
|
required: false,
|
|
935
|
-
type:
|
|
1227
|
+
type: mongoose12.Schema.Types.ObjectId
|
|
936
1228
|
},
|
|
937
1229
|
eventType: {
|
|
938
1230
|
enum: Object.values(EnumEventType),
|
|
@@ -971,24 +1263,24 @@ var schema4 = new MongooseSchema8(
|
|
|
971
1263
|
},
|
|
972
1264
|
{ timestamps: true }
|
|
973
1265
|
);
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
var GoogleImportedMarketModel =
|
|
1266
|
+
schema8.index({ "location.geo": "2dsphere" });
|
|
1267
|
+
schema8.index({ name: 1 });
|
|
1268
|
+
schema8.index({ region: 1 });
|
|
1269
|
+
schema8.index({ deletedAt: 1 });
|
|
1270
|
+
schema8.index({ "dateTime.dateStatus": 1 });
|
|
1271
|
+
schema8.index({ slug: 1 });
|
|
1272
|
+
schema8.index({ name: "text", description: "text" });
|
|
1273
|
+
schema8.plugin(searchNamePlugin);
|
|
1274
|
+
var GoogleImportedMarketModel = mongoose12.models.GoogleImportedMarket || mongoose12.model("GoogleImportedMarket", schema8);
|
|
983
1275
|
|
|
984
1276
|
// src/mongoose/Notification.ts
|
|
985
1277
|
import {
|
|
986
1278
|
EnumNotificationResourceType,
|
|
987
1279
|
EnumNotificationType
|
|
988
1280
|
} from "@timardex/cluemart-shared";
|
|
989
|
-
import
|
|
990
|
-
var MongooseSchema9 =
|
|
991
|
-
var
|
|
1281
|
+
import mongoose13 from "mongoose";
|
|
1282
|
+
var MongooseSchema9 = mongoose13.Schema;
|
|
1283
|
+
var schema9 = new MongooseSchema9(
|
|
992
1284
|
{
|
|
993
1285
|
data: {
|
|
994
1286
|
resourceId: { required: true, type: String },
|
|
@@ -1011,20 +1303,20 @@ var schema5 = new MongooseSchema9(
|
|
|
1011
1303
|
userId: {
|
|
1012
1304
|
ref: "User",
|
|
1013
1305
|
required: true,
|
|
1014
|
-
type:
|
|
1306
|
+
type: mongoose13.Schema.Types.ObjectId
|
|
1015
1307
|
}
|
|
1016
1308
|
},
|
|
1017
1309
|
{ timestamps: true }
|
|
1018
1310
|
);
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
var NotificationModel =
|
|
1311
|
+
schema9.index({ isRead: 1, userId: 1 });
|
|
1312
|
+
schema9.index({ createdAt: -1, userId: 1 });
|
|
1313
|
+
var NotificationModel = mongoose13.models.Notification || mongoose13.model("Notification", schema9);
|
|
1022
1314
|
|
|
1023
1315
|
// src/mongoose/PushToken.ts
|
|
1024
1316
|
import { EnumOSPlatform } from "@timardex/cluemart-shared/enums";
|
|
1025
|
-
import
|
|
1026
|
-
var MongooseSchema10 =
|
|
1027
|
-
var
|
|
1317
|
+
import mongoose14 from "mongoose";
|
|
1318
|
+
var MongooseSchema10 = mongoose14.Schema;
|
|
1319
|
+
var schema10 = new MongooseSchema10(
|
|
1028
1320
|
{
|
|
1029
1321
|
platform: {
|
|
1030
1322
|
enum: Object.values(EnumOSPlatform),
|
|
@@ -1035,12 +1327,12 @@ var schema6 = new MongooseSchema10(
|
|
|
1035
1327
|
userId: {
|
|
1036
1328
|
ref: "User",
|
|
1037
1329
|
required: true,
|
|
1038
|
-
type:
|
|
1330
|
+
type: mongoose14.Schema.Types.ObjectId
|
|
1039
1331
|
}
|
|
1040
1332
|
},
|
|
1041
1333
|
{ timestamps: true }
|
|
1042
1334
|
);
|
|
1043
|
-
var PushTokenModel =
|
|
1335
|
+
var PushTokenModel = mongoose14.models.PushToken || mongoose14.model("PushToken", schema10);
|
|
1044
1336
|
|
|
1045
1337
|
// src/mongoose/ResourceActivity.ts
|
|
1046
1338
|
import {
|
|
@@ -1049,8 +1341,8 @@ import {
|
|
|
1049
1341
|
EnumOSPlatform as EnumOSPlatform2,
|
|
1050
1342
|
EnumResourceType as EnumResourceType3
|
|
1051
1343
|
} from "@timardex/cluemart-shared";
|
|
1052
|
-
import
|
|
1053
|
-
var MongooseSchema11 =
|
|
1344
|
+
import mongoose15 from "mongoose";
|
|
1345
|
+
var MongooseSchema11 = mongoose15.Schema;
|
|
1054
1346
|
var ActivitySchema = new MongooseSchema11(
|
|
1055
1347
|
{
|
|
1056
1348
|
activityType: {
|
|
@@ -1079,7 +1371,7 @@ var ActivitySchema = new MongooseSchema11(
|
|
|
1079
1371
|
},
|
|
1080
1372
|
{ _id: false }
|
|
1081
1373
|
);
|
|
1082
|
-
var
|
|
1374
|
+
var schema11 = new MongooseSchema11(
|
|
1083
1375
|
{
|
|
1084
1376
|
activity: { default: [], type: [ActivitySchema] },
|
|
1085
1377
|
resourceId: { required: true, type: String },
|
|
@@ -1091,9 +1383,9 @@ var schema7 = new MongooseSchema11(
|
|
|
1091
1383
|
},
|
|
1092
1384
|
{ timestamps: true }
|
|
1093
1385
|
);
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
var ResourceActivityModel =
|
|
1386
|
+
schema11.index({ resourceId: 1, resourceType: 1 }, { unique: true });
|
|
1387
|
+
schema11.index({ "views.location": "2dsphere" });
|
|
1388
|
+
var ResourceActivityModel = mongoose15.models.ResourceActivity || mongoose15.model("ResourceActivity", schema11);
|
|
1097
1389
|
|
|
1098
1390
|
// src/mongoose/User.ts
|
|
1099
1391
|
import {
|
|
@@ -1106,15 +1398,15 @@ import {
|
|
|
1106
1398
|
EnumUserLicence as EnumUserLicence3,
|
|
1107
1399
|
EnumUserRole
|
|
1108
1400
|
} from "@timardex/cluemart-shared";
|
|
1109
|
-
import
|
|
1110
|
-
var MongooseSchema12 =
|
|
1401
|
+
import mongoose16 from "mongoose";
|
|
1402
|
+
var MongooseSchema12 = mongoose16.Schema;
|
|
1111
1403
|
var userActivityEventSchema = new MongooseSchema12(
|
|
1112
1404
|
{
|
|
1113
1405
|
dateTime: dateTimeSchema2,
|
|
1114
1406
|
resourceId: {
|
|
1115
1407
|
ref: "Event",
|
|
1116
1408
|
required: false,
|
|
1117
|
-
type:
|
|
1409
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1118
1410
|
}
|
|
1119
1411
|
},
|
|
1120
1412
|
{ _id: false }
|
|
@@ -1124,17 +1416,17 @@ var userActivityFavouritesSchema = new MongooseSchema12(
|
|
|
1124
1416
|
events: {
|
|
1125
1417
|
ref: "Event",
|
|
1126
1418
|
required: false,
|
|
1127
|
-
type: [
|
|
1419
|
+
type: [mongoose16.Schema.Types.ObjectId]
|
|
1128
1420
|
},
|
|
1129
1421
|
partners: {
|
|
1130
1422
|
ref: "Partner",
|
|
1131
1423
|
required: false,
|
|
1132
|
-
type: [
|
|
1424
|
+
type: [mongoose16.Schema.Types.ObjectId]
|
|
1133
1425
|
},
|
|
1134
1426
|
vendors: {
|
|
1135
1427
|
ref: "Vendor",
|
|
1136
1428
|
required: false,
|
|
1137
|
-
type: [
|
|
1429
|
+
type: [mongoose16.Schema.Types.ObjectId]
|
|
1138
1430
|
}
|
|
1139
1431
|
},
|
|
1140
1432
|
{ _id: false }
|
|
@@ -1163,6 +1455,18 @@ var stripeSchema = new MongooseSchema12(
|
|
|
1163
1455
|
required: false,
|
|
1164
1456
|
type: Date
|
|
1165
1457
|
},
|
|
1458
|
+
paymentFailedAt: {
|
|
1459
|
+
required: false,
|
|
1460
|
+
type: Date
|
|
1461
|
+
},
|
|
1462
|
+
paymentGracePeriodEndsAt: {
|
|
1463
|
+
required: false,
|
|
1464
|
+
type: Date
|
|
1465
|
+
},
|
|
1466
|
+
paymentGraceSubscriptionId: {
|
|
1467
|
+
required: false,
|
|
1468
|
+
type: String
|
|
1469
|
+
},
|
|
1166
1470
|
pendingBillingPeriod: {
|
|
1167
1471
|
enum: Object.values(EnumBillingPeriod2),
|
|
1168
1472
|
required: false,
|
|
@@ -1221,13 +1525,13 @@ var redeemedRewardSchema = new MongooseSchema12(
|
|
|
1221
1525
|
},
|
|
1222
1526
|
{ _id: false }
|
|
1223
1527
|
);
|
|
1224
|
-
var
|
|
1528
|
+
var schema12 = new MongooseSchema12(
|
|
1225
1529
|
{
|
|
1226
1530
|
active: { default: false, required: true, type: Boolean },
|
|
1227
1531
|
affiliate: {
|
|
1228
1532
|
ref: "Affiliate",
|
|
1229
1533
|
required: false,
|
|
1230
|
-
type:
|
|
1534
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1231
1535
|
},
|
|
1232
1536
|
avatar: {
|
|
1233
1537
|
required: false,
|
|
@@ -1236,7 +1540,7 @@ var schema8 = new MongooseSchema12(
|
|
|
1236
1540
|
coupon: {
|
|
1237
1541
|
ref: "Coupon",
|
|
1238
1542
|
required: false,
|
|
1239
|
-
type:
|
|
1543
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1240
1544
|
},
|
|
1241
1545
|
deletedAt: { default: null, required: false, type: Date },
|
|
1242
1546
|
email: { required: true, type: String },
|
|
@@ -1248,13 +1552,13 @@ var schema8 = new MongooseSchema12(
|
|
|
1248
1552
|
events: {
|
|
1249
1553
|
ref: "Event",
|
|
1250
1554
|
required: false,
|
|
1251
|
-
type: [
|
|
1555
|
+
type: [mongoose16.Schema.Types.ObjectId]
|
|
1252
1556
|
},
|
|
1253
1557
|
firstName: { required: true, type: String },
|
|
1254
1558
|
game: {
|
|
1255
1559
|
ref: "Game",
|
|
1256
1560
|
required: false,
|
|
1257
|
-
type:
|
|
1561
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1258
1562
|
},
|
|
1259
1563
|
interests: {
|
|
1260
1564
|
enum: Object.values(EnumResourceType4),
|
|
@@ -1276,7 +1580,7 @@ var schema8 = new MongooseSchema12(
|
|
|
1276
1580
|
partner: {
|
|
1277
1581
|
ref: "Partner",
|
|
1278
1582
|
required: false,
|
|
1279
|
-
type:
|
|
1583
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1280
1584
|
},
|
|
1281
1585
|
password: { required: true, type: String },
|
|
1282
1586
|
platform: {
|
|
@@ -1309,7 +1613,7 @@ var schema8 = new MongooseSchema12(
|
|
|
1309
1613
|
school: {
|
|
1310
1614
|
ref: "School",
|
|
1311
1615
|
required: false,
|
|
1312
|
-
type:
|
|
1616
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1313
1617
|
},
|
|
1314
1618
|
stripe: {
|
|
1315
1619
|
required: false,
|
|
@@ -1334,20 +1638,20 @@ var schema8 = new MongooseSchema12(
|
|
|
1334
1638
|
vendor: {
|
|
1335
1639
|
ref: "Vendor",
|
|
1336
1640
|
required: false,
|
|
1337
|
-
type:
|
|
1641
|
+
type: mongoose16.Schema.Types.ObjectId
|
|
1338
1642
|
}
|
|
1339
1643
|
},
|
|
1340
1644
|
{ strict: false, timestamps: true }
|
|
1341
1645
|
);
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
var UserModel =
|
|
1646
|
+
schema12.index({ "licences.expiryDate": 1 });
|
|
1647
|
+
schema12.index({ "licences.licenceType": 1 });
|
|
1648
|
+
schema12.index({ promoCodes: 1, active: 1, deletedAt: 1 });
|
|
1649
|
+
var UserModel = mongoose16.models.User || mongoose16.model("User", schema12);
|
|
1346
1650
|
|
|
1347
1651
|
// src/mongoose/VerificationToken.ts
|
|
1348
|
-
import
|
|
1349
|
-
var MongooseSchema13 =
|
|
1350
|
-
var
|
|
1652
|
+
import mongoose17 from "mongoose";
|
|
1653
|
+
var MongooseSchema13 = mongoose17.Schema;
|
|
1654
|
+
var schema13 = new MongooseSchema13(
|
|
1351
1655
|
{
|
|
1352
1656
|
createdAt: {
|
|
1353
1657
|
default: Date.now,
|
|
@@ -1362,15 +1666,15 @@ var schema9 = new MongooseSchema13(
|
|
|
1362
1666
|
},
|
|
1363
1667
|
{ timestamps: true }
|
|
1364
1668
|
);
|
|
1365
|
-
var VerificationTokenModel =
|
|
1669
|
+
var VerificationTokenModel = mongoose17.models.VerificationToken || mongoose17.model("VerificationToken", schema13);
|
|
1366
1670
|
|
|
1367
1671
|
// src/mongoose/vendor/Vendor.ts
|
|
1368
1672
|
import {
|
|
1369
1673
|
EnumEventDateStatus as EnumEventDateStatus5,
|
|
1370
1674
|
EnumVendorType
|
|
1371
1675
|
} from "@timardex/cluemart-shared";
|
|
1372
|
-
import
|
|
1373
|
-
var MongooseSchema14 =
|
|
1676
|
+
import mongoose18 from "mongoose";
|
|
1677
|
+
var MongooseSchema14 = mongoose18.Schema;
|
|
1374
1678
|
var vendorProductTypeSchema = new MongooseSchema14(
|
|
1375
1679
|
{
|
|
1376
1680
|
description: { required: false, type: String },
|
|
@@ -1417,15 +1721,27 @@ var calendarWrapperSchema = new MongooseSchema14(
|
|
|
1417
1721
|
},
|
|
1418
1722
|
{ _id: false }
|
|
1419
1723
|
);
|
|
1420
|
-
var
|
|
1724
|
+
var vendorAvailabilitySchema = new MongooseSchema14(
|
|
1725
|
+
{
|
|
1726
|
+
corporate: { default: false, required: false, type: Boolean },
|
|
1727
|
+
private: { default: false, required: false, type: Boolean },
|
|
1728
|
+
school: { default: false, required: false, type: Boolean }
|
|
1729
|
+
},
|
|
1730
|
+
{ _id: false }
|
|
1731
|
+
);
|
|
1732
|
+
var downgradeSnapshotSchema = new MongooseSchema14(
|
|
1733
|
+
{
|
|
1734
|
+
availability: { required: false, type: vendorAvailabilitySchema },
|
|
1735
|
+
calendarActive: { required: false, type: Boolean },
|
|
1736
|
+
productsActive: { required: false, type: Boolean }
|
|
1737
|
+
},
|
|
1738
|
+
{ _id: false }
|
|
1739
|
+
);
|
|
1740
|
+
var schema14 = new MongooseSchema14(
|
|
1421
1741
|
{
|
|
1422
1742
|
...baseResourceFields,
|
|
1423
1743
|
// Importing base resource fields from global.ts
|
|
1424
|
-
availability: {
|
|
1425
|
-
corporate: { default: false, required: false, type: Boolean },
|
|
1426
|
-
private: { default: false, required: false, type: Boolean },
|
|
1427
|
-
school: { default: false, required: false, type: Boolean }
|
|
1428
|
-
},
|
|
1744
|
+
availability: { required: false, type: vendorAvailabilitySchema },
|
|
1429
1745
|
calendar: {
|
|
1430
1746
|
required: false,
|
|
1431
1747
|
type: calendarWrapperSchema
|
|
@@ -1433,6 +1749,7 @@ var schema10 = new MongooseSchema14(
|
|
|
1433
1749
|
categories: { required: true, type: [CategorySchema] },
|
|
1434
1750
|
categoriesNames: { default: [], required: false, type: [String] },
|
|
1435
1751
|
claimed: { default: true, required: false, type: Boolean },
|
|
1752
|
+
downgradeSnapshot: { required: false, type: downgradeSnapshotSchema },
|
|
1436
1753
|
foodTruck: { required: true, type: Boolean },
|
|
1437
1754
|
products: { required: false, type: productWrapperSchema },
|
|
1438
1755
|
relations: {
|
|
@@ -1444,12 +1761,12 @@ var schema10 = new MongooseSchema14(
|
|
|
1444
1761
|
unregisteredVendorId: {
|
|
1445
1762
|
ref: "UnregisteredVendor",
|
|
1446
1763
|
required: false,
|
|
1447
|
-
type:
|
|
1764
|
+
type: mongoose18.Schema.Types.ObjectId
|
|
1448
1765
|
},
|
|
1449
1766
|
vendorInfoId: {
|
|
1450
1767
|
ref: "VendorInfo",
|
|
1451
1768
|
required: false,
|
|
1452
|
-
type:
|
|
1769
|
+
type: mongoose18.Schema.Types.ObjectId
|
|
1453
1770
|
},
|
|
1454
1771
|
vendorType: {
|
|
1455
1772
|
enum: Object.values(EnumVendorType),
|
|
@@ -1459,26 +1776,26 @@ var schema10 = new MongooseSchema14(
|
|
|
1459
1776
|
},
|
|
1460
1777
|
{ timestamps: true }
|
|
1461
1778
|
);
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1779
|
+
schema14.index({ name: 1 });
|
|
1780
|
+
schema14.index({ description: 1 });
|
|
1781
|
+
schema14.index({ region: 1 });
|
|
1782
|
+
schema14.index({ "categories.name": 1 });
|
|
1783
|
+
schema14.index({ slug: 1 });
|
|
1784
|
+
schema14.index({
|
|
1785
|
+
categoriesNames: "text",
|
|
1469
1786
|
description: "text",
|
|
1470
|
-
|
|
1787
|
+
name: "text"
|
|
1471
1788
|
});
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
var VendorModel =
|
|
1789
|
+
schema14.index({ deletedAt: 1, "owner.userId": 1 });
|
|
1790
|
+
schema14.plugin(searchNamePlugin);
|
|
1791
|
+
var VendorModel = mongoose18.models.Vendor || mongoose18.model("Vendor", schema14);
|
|
1475
1792
|
|
|
1476
1793
|
// src/mongoose/vendor/VendorInfo.ts
|
|
1477
1794
|
import {
|
|
1478
1795
|
EnumFoodFlavor
|
|
1479
1796
|
} from "@timardex/cluemart-shared";
|
|
1480
|
-
import
|
|
1481
|
-
var MongooseSchema15 =
|
|
1797
|
+
import mongoose19 from "mongoose";
|
|
1798
|
+
var MongooseSchema15 = mongoose19.Schema;
|
|
1482
1799
|
var AttributesSchema = new MongooseSchema15(
|
|
1483
1800
|
{
|
|
1484
1801
|
details: { required: false, type: String },
|
|
@@ -1486,7 +1803,7 @@ var AttributesSchema = new MongooseSchema15(
|
|
|
1486
1803
|
},
|
|
1487
1804
|
{ _id: false }
|
|
1488
1805
|
);
|
|
1489
|
-
var
|
|
1806
|
+
var schema15 = new MongooseSchema15(
|
|
1490
1807
|
{
|
|
1491
1808
|
active: { default: true, type: Boolean },
|
|
1492
1809
|
compliance: {
|
|
@@ -1521,29 +1838,29 @@ var schema11 = new MongooseSchema15(
|
|
|
1521
1838
|
vendorId: {
|
|
1522
1839
|
ref: "Vendor",
|
|
1523
1840
|
required: true,
|
|
1524
|
-
type:
|
|
1841
|
+
type: mongoose19.Schema.Types.ObjectId
|
|
1525
1842
|
}
|
|
1526
1843
|
},
|
|
1527
1844
|
{ timestamps: true }
|
|
1528
1845
|
);
|
|
1529
|
-
|
|
1530
|
-
var VendorInfoModel =
|
|
1846
|
+
schema15.index({ vendorId: 1 });
|
|
1847
|
+
var VendorInfoModel = mongoose19.models.VendorInfo || mongoose19.model("VendorInfo", schema15);
|
|
1531
1848
|
|
|
1532
1849
|
// src/mongoose/vendor/UnregisteredVendor.ts
|
|
1533
|
-
import
|
|
1534
|
-
var MongooseSchema16 =
|
|
1850
|
+
import mongoose20 from "mongoose";
|
|
1851
|
+
var MongooseSchema16 = mongoose20.Schema;
|
|
1535
1852
|
var invitationSchema = new MongooseSchema16(
|
|
1536
1853
|
{
|
|
1537
1854
|
dateTime: { required: true, type: [dateTimeSchema2] },
|
|
1538
1855
|
inviterId: {
|
|
1539
1856
|
ref: "Event",
|
|
1540
1857
|
required: true,
|
|
1541
|
-
type:
|
|
1858
|
+
type: mongoose20.Schema.Types.ObjectId
|
|
1542
1859
|
}
|
|
1543
1860
|
},
|
|
1544
1861
|
{ _id: false }
|
|
1545
1862
|
);
|
|
1546
|
-
var
|
|
1863
|
+
var schema16 = new MongooseSchema16(
|
|
1547
1864
|
{
|
|
1548
1865
|
active: { default: true, required: true, type: Boolean },
|
|
1549
1866
|
categoryIds: { required: true, type: [String] },
|
|
@@ -1552,7 +1869,7 @@ var schema12 = new MongooseSchema16(
|
|
|
1552
1869
|
claimedByUserId: {
|
|
1553
1870
|
ref: "User",
|
|
1554
1871
|
required: false,
|
|
1555
|
-
type:
|
|
1872
|
+
type: mongoose20.Schema.Types.ObjectId
|
|
1556
1873
|
},
|
|
1557
1874
|
claimInitiatedAt: { default: null, required: false, type: Date },
|
|
1558
1875
|
claimToken: { default: null, required: false, type: String },
|
|
@@ -1565,15 +1882,15 @@ var schema12 = new MongooseSchema16(
|
|
|
1565
1882
|
},
|
|
1566
1883
|
{ timestamps: true }
|
|
1567
1884
|
);
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
var UnregisteredVendorModel =
|
|
1885
|
+
schema16.index({ name: 1 });
|
|
1886
|
+
schema16.index({ email: 1 });
|
|
1887
|
+
var UnregisteredVendorModel = mongoose20.models.UnregisteredVendor || mongoose20.model("UnregisteredVendor", schema16);
|
|
1571
1888
|
|
|
1572
1889
|
// src/mongoose/event/Event.ts
|
|
1573
1890
|
import { EnumEventType as EnumEventType2 } from "@timardex/cluemart-shared";
|
|
1574
|
-
import
|
|
1575
|
-
var MongooseSchema17 =
|
|
1576
|
-
var
|
|
1891
|
+
import mongoose21 from "mongoose";
|
|
1892
|
+
var MongooseSchema17 = mongoose21.Schema;
|
|
1893
|
+
var schema17 = new MongooseSchema17(
|
|
1577
1894
|
{
|
|
1578
1895
|
...baseResourceFields,
|
|
1579
1896
|
// Importing base resource fields from global.ts
|
|
@@ -1582,7 +1899,7 @@ var schema13 = new MongooseSchema17(
|
|
|
1582
1899
|
eventInfoId: {
|
|
1583
1900
|
ref: "EventInfo",
|
|
1584
1901
|
required: false,
|
|
1585
|
-
type:
|
|
1902
|
+
type: mongoose21.Schema.Types.ObjectId
|
|
1586
1903
|
},
|
|
1587
1904
|
eventType: {
|
|
1588
1905
|
enum: Object.values(EnumEventType2),
|
|
@@ -1611,24 +1928,24 @@ var schema13 = new MongooseSchema17(
|
|
|
1611
1928
|
},
|
|
1612
1929
|
{ timestamps: true }
|
|
1613
1930
|
);
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
var EventModel =
|
|
1931
|
+
schema17.index({ name: 1 });
|
|
1932
|
+
schema17.index({ description: 1 });
|
|
1933
|
+
schema17.index({ region: 1 });
|
|
1934
|
+
schema17.index({ "location.geo": "2dsphere" });
|
|
1935
|
+
schema17.index({ tags: 1 });
|
|
1936
|
+
schema17.index({ deletedAt: 1 });
|
|
1937
|
+
schema17.index({ "dateTime.dateStatus": 1 });
|
|
1938
|
+
schema17.index({ slug: 1 });
|
|
1939
|
+
schema17.index({ name: "text", description: "text", tags: "text" });
|
|
1940
|
+
schema17.index({ "owner.userId": 1, deletedAt: 1 });
|
|
1941
|
+
schema17.plugin(searchNamePlugin);
|
|
1942
|
+
var EventModel = mongoose21.models.Event || mongoose21.model("Event", schema17);
|
|
1626
1943
|
|
|
1627
1944
|
// src/mongoose/Partner.ts
|
|
1628
1945
|
import { EnumPartnerType } from "@timardex/cluemart-shared";
|
|
1629
|
-
import
|
|
1630
|
-
var MongooseSchema18 =
|
|
1631
|
-
var
|
|
1946
|
+
import mongoose22 from "mongoose";
|
|
1947
|
+
var MongooseSchema18 = mongoose22.Schema;
|
|
1948
|
+
var schema18 = new MongooseSchema18(
|
|
1632
1949
|
{
|
|
1633
1950
|
...baseResourceFields,
|
|
1634
1951
|
location: {
|
|
@@ -1644,15 +1961,15 @@ var schema14 = new MongooseSchema18(
|
|
|
1644
1961
|
},
|
|
1645
1962
|
{ timestamps: true }
|
|
1646
1963
|
);
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
var PartnerModel =
|
|
1964
|
+
schema18.index({ name: 1 });
|
|
1965
|
+
schema18.index({ description: 1 });
|
|
1966
|
+
schema18.index({ region: 1 });
|
|
1967
|
+
schema18.index({ "location.geo": "2dsphere" });
|
|
1968
|
+
schema18.index({ slug: 1 });
|
|
1969
|
+
schema18.index({ name: "text", description: "text" });
|
|
1970
|
+
schema18.index({ "owner.userId": 1, deletedAt: 1 });
|
|
1971
|
+
schema18.plugin(searchNamePlugin);
|
|
1972
|
+
var PartnerModel = mongoose22.models.Partner || mongoose22.model("Partner", schema18);
|
|
1656
1973
|
|
|
1657
1974
|
// src/mongoose/Post.ts
|
|
1658
1975
|
import {
|
|
@@ -1660,8 +1977,8 @@ import {
|
|
|
1660
1977
|
EnumPostType as EnumPostType2,
|
|
1661
1978
|
EnumResourceType as EnumResourceType5
|
|
1662
1979
|
} from "@timardex/cluemart-shared";
|
|
1663
|
-
import
|
|
1664
|
-
var MongooseSchema19 =
|
|
1980
|
+
import mongoose23, { Schema } from "mongoose";
|
|
1981
|
+
var MongooseSchema19 = mongoose23.Schema;
|
|
1665
1982
|
var contentSchema = new MongooseSchema19(
|
|
1666
1983
|
{
|
|
1667
1984
|
contentData: Schema.Types.Mixed,
|
|
@@ -1687,7 +2004,7 @@ var resourceSchema = new MongooseSchema19(
|
|
|
1687
2004
|
},
|
|
1688
2005
|
{ _id: false }
|
|
1689
2006
|
);
|
|
1690
|
-
var
|
|
2007
|
+
var schema19 = new MongooseSchema19(
|
|
1691
2008
|
{
|
|
1692
2009
|
active: { default: false, required: true, type: Boolean },
|
|
1693
2010
|
approvedAt: { default: null, required: false, type: Date },
|
|
@@ -1718,14 +2035,14 @@ var schema15 = new MongooseSchema19(
|
|
|
1718
2035
|
},
|
|
1719
2036
|
{ timestamps: true }
|
|
1720
2037
|
);
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
var PostModel =
|
|
2038
|
+
schema19.index({ title: 1 });
|
|
2039
|
+
schema19.index({ tags: 1 });
|
|
2040
|
+
schema19.index({ postType: 1, slug: 1 }, { unique: true });
|
|
2041
|
+
var PostModel = mongoose23.models.Post || mongoose23.model("Post", schema19);
|
|
1725
2042
|
|
|
1726
2043
|
// src/mongoose/AppSetting.ts
|
|
1727
|
-
import
|
|
1728
|
-
var MongooseSchema20 =
|
|
2044
|
+
import mongoose24 from "mongoose";
|
|
2045
|
+
var MongooseSchema20 = mongoose24.Schema;
|
|
1729
2046
|
var APP_SETTINGS_ID = "APP_SETTINGS_DOCUMENT_ID";
|
|
1730
2047
|
var AppSettingSchema = new MongooseSchema20(
|
|
1731
2048
|
{
|
|
@@ -1758,21 +2075,21 @@ var AppSettingSchema = new MongooseSchema20(
|
|
|
1758
2075
|
},
|
|
1759
2076
|
{ timestamps: true }
|
|
1760
2077
|
);
|
|
1761
|
-
var AppSettingModel =
|
|
2078
|
+
var AppSettingModel = mongoose24.models.AppSetting || mongoose24.model("AppSetting", AppSettingSchema);
|
|
1762
2079
|
|
|
1763
2080
|
// src/mongoose/game/Game.ts
|
|
1764
2081
|
import {
|
|
1765
2082
|
EnumGameStatus,
|
|
1766
2083
|
EnumGameType
|
|
1767
2084
|
} from "@timardex/cluemart-shared";
|
|
1768
|
-
import
|
|
2085
|
+
import mongoose28 from "mongoose";
|
|
1769
2086
|
|
|
1770
2087
|
// src/mongoose/game/DailyClue.ts
|
|
1771
|
-
import
|
|
2088
|
+
import mongoose26 from "mongoose";
|
|
1772
2089
|
|
|
1773
2090
|
// src/mongoose/game/utils.ts
|
|
1774
|
-
import
|
|
1775
|
-
var MongooseSchema21 =
|
|
2091
|
+
import mongoose25 from "mongoose";
|
|
2092
|
+
var MongooseSchema21 = mongoose25.Schema;
|
|
1776
2093
|
var schemaGameDate = new MongooseSchema21(
|
|
1777
2094
|
{
|
|
1778
2095
|
endDate: { required: true, type: Date },
|
|
@@ -1782,7 +2099,7 @@ var schemaGameDate = new MongooseSchema21(
|
|
|
1782
2099
|
);
|
|
1783
2100
|
|
|
1784
2101
|
// src/mongoose/game/DailyClue.ts
|
|
1785
|
-
var MongooseSchema22 =
|
|
2102
|
+
var MongooseSchema22 = mongoose26.Schema;
|
|
1786
2103
|
var schemaLetters = new MongooseSchema22(
|
|
1787
2104
|
{
|
|
1788
2105
|
collected: { required: false, type: [String] },
|
|
@@ -1813,8 +2130,8 @@ var schemaDailyClueGameData = new MongooseSchema22(
|
|
|
1813
2130
|
);
|
|
1814
2131
|
|
|
1815
2132
|
// src/mongoose/game/PuzzleGame.ts
|
|
1816
|
-
import
|
|
1817
|
-
var MongooseSchema23 =
|
|
2133
|
+
import mongoose27 from "mongoose";
|
|
2134
|
+
var MongooseSchema23 = mongoose27.Schema;
|
|
1818
2135
|
var schemaPuzzleAnswer = new MongooseSchema23(
|
|
1819
2136
|
{
|
|
1820
2137
|
answer: { required: true, type: String },
|
|
@@ -1859,16 +2176,16 @@ var schemaPuzzleGameData = new MongooseSchema23(
|
|
|
1859
2176
|
);
|
|
1860
2177
|
|
|
1861
2178
|
// src/mongoose/game/Game.ts
|
|
1862
|
-
var MongooseSchema24 =
|
|
2179
|
+
var MongooseSchema24 = mongoose28.Schema;
|
|
1863
2180
|
var gameDataSchemas = {
|
|
1864
2181
|
[EnumGameType.DAILY_CLUE]: schemaDailyClueGameData,
|
|
1865
2182
|
[EnumGameType.MINI_QUIZ]: schemaPuzzleGameData,
|
|
1866
2183
|
[EnumGameType.ODD_ONE_OUT]: schemaPuzzleGameData
|
|
1867
2184
|
};
|
|
1868
2185
|
var gameDataDefinition = Object.fromEntries(
|
|
1869
|
-
Object.entries(gameDataSchemas).map(([key,
|
|
2186
|
+
Object.entries(gameDataSchemas).map(([key, schema24]) => [
|
|
1870
2187
|
key,
|
|
1871
|
-
{ default: null, required: false, type:
|
|
2188
|
+
{ default: null, required: false, type: schema24 }
|
|
1872
2189
|
])
|
|
1873
2190
|
);
|
|
1874
2191
|
var gameHistorySchema = new MongooseSchema24(
|
|
@@ -1906,7 +2223,7 @@ var gameTypeSchema = new MongooseSchema24(
|
|
|
1906
2223
|
},
|
|
1907
2224
|
{ timestamps: true }
|
|
1908
2225
|
);
|
|
1909
|
-
var
|
|
2226
|
+
var schema20 = new MongooseSchema24(
|
|
1910
2227
|
{
|
|
1911
2228
|
active: { default: false, required: true, type: Boolean },
|
|
1912
2229
|
deletedAt: { default: null, required: false, type: Date },
|
|
@@ -1919,11 +2236,11 @@ var schema16 = new MongooseSchema24(
|
|
|
1919
2236
|
},
|
|
1920
2237
|
{ timestamps: true }
|
|
1921
2238
|
);
|
|
1922
|
-
var GameModel =
|
|
2239
|
+
var GameModel = mongoose28.models.Game || mongoose28.model("Game", schema20);
|
|
1923
2240
|
|
|
1924
2241
|
// src/mongoose/School.ts
|
|
1925
|
-
import
|
|
1926
|
-
var MongooseSchema25 =
|
|
2242
|
+
import mongoose29 from "mongoose";
|
|
2243
|
+
var MongooseSchema25 = mongoose29.Schema;
|
|
1927
2244
|
var campaignsSchema = new MongooseSchema25(
|
|
1928
2245
|
{
|
|
1929
2246
|
endDate: { required: true, type: Date },
|
|
@@ -1932,7 +2249,7 @@ var campaignsSchema = new MongooseSchema25(
|
|
|
1932
2249
|
},
|
|
1933
2250
|
{ _id: false }
|
|
1934
2251
|
);
|
|
1935
|
-
var
|
|
2252
|
+
var schema21 = new MongooseSchema25(
|
|
1936
2253
|
{
|
|
1937
2254
|
// New schools are active by default
|
|
1938
2255
|
active: { default: false, required: true, type: Boolean },
|
|
@@ -1959,14 +2276,14 @@ var schema17 = new MongooseSchema25(
|
|
|
1959
2276
|
},
|
|
1960
2277
|
{ timestamps: true }
|
|
1961
2278
|
);
|
|
1962
|
-
|
|
2279
|
+
schema21.index(
|
|
1963
2280
|
{ schoolCode: 1 },
|
|
1964
2281
|
{
|
|
1965
2282
|
partialFilterExpression: { active: true, deletedAt: null },
|
|
1966
2283
|
unique: true
|
|
1967
2284
|
}
|
|
1968
2285
|
);
|
|
1969
|
-
var SchoolModel =
|
|
2286
|
+
var SchoolModel = mongoose29.models.School || mongoose29.model("School", schema21);
|
|
1970
2287
|
|
|
1971
2288
|
// src/mongoose/Affiliate.ts
|
|
1972
2289
|
import {
|
|
@@ -1974,8 +2291,8 @@ import {
|
|
|
1974
2291
|
EnumAffiliateRewardType,
|
|
1975
2292
|
EnumResourceType as EnumResourceType6
|
|
1976
2293
|
} from "@timardex/cluemart-shared";
|
|
1977
|
-
import
|
|
1978
|
-
var MongooseSchema26 =
|
|
2294
|
+
import mongoose30 from "mongoose";
|
|
2295
|
+
var MongooseSchema26 = mongoose30.Schema;
|
|
1979
2296
|
var affiliateRewardSchema = new MongooseSchema26(
|
|
1980
2297
|
{
|
|
1981
2298
|
createdAt: { required: true, type: Date },
|
|
@@ -1996,7 +2313,7 @@ var affiliateResourceSchema = new MongooseSchema26(
|
|
|
1996
2313
|
resourceDeletedAt: { default: null, required: false, type: Date },
|
|
1997
2314
|
resourceId: {
|
|
1998
2315
|
required: true,
|
|
1999
|
-
type:
|
|
2316
|
+
type: mongoose30.Schema.Types.ObjectId
|
|
2000
2317
|
},
|
|
2001
2318
|
resourceName: { required: true, type: String },
|
|
2002
2319
|
resourceOwner: {
|
|
@@ -2059,7 +2376,7 @@ var redeemHistorySchema = new MongooseSchema26(
|
|
|
2059
2376
|
},
|
|
2060
2377
|
{ _id: false }
|
|
2061
2378
|
);
|
|
2062
|
-
var
|
|
2379
|
+
var schema22 = new MongooseSchema26(
|
|
2063
2380
|
{
|
|
2064
2381
|
active: { default: false, required: true, type: Boolean },
|
|
2065
2382
|
affiliateBonusRewards: {
|
|
@@ -2089,22 +2406,22 @@ var schema18 = new MongooseSchema26(
|
|
|
2089
2406
|
},
|
|
2090
2407
|
{ timestamps: true }
|
|
2091
2408
|
);
|
|
2092
|
-
|
|
2409
|
+
schema22.index(
|
|
2093
2410
|
{ affiliateCode: 1 },
|
|
2094
2411
|
{
|
|
2095
2412
|
partialFilterExpression: { active: true, deletedAt: null },
|
|
2096
2413
|
unique: true
|
|
2097
2414
|
}
|
|
2098
2415
|
);
|
|
2099
|
-
var AffiliateModel =
|
|
2416
|
+
var AffiliateModel = mongoose30.models.Affiliate || mongoose30.model("Affiliate", schema22);
|
|
2100
2417
|
|
|
2101
2418
|
// src/mongoose/Coupon.ts
|
|
2102
2419
|
import {
|
|
2103
2420
|
EnumCouponQualificationType,
|
|
2104
2421
|
EnumResourceType as EnumResourceType7
|
|
2105
2422
|
} from "@timardex/cluemart-shared";
|
|
2106
|
-
import
|
|
2107
|
-
var MongooseSchema27 =
|
|
2423
|
+
import mongoose31 from "mongoose";
|
|
2424
|
+
var MongooseSchema27 = mongoose31.Schema;
|
|
2108
2425
|
var couponOptionSchema = new MongooseSchema27(
|
|
2109
2426
|
{
|
|
2110
2427
|
buy: { required: false, type: Number },
|
|
@@ -2124,20 +2441,20 @@ var couponVendorProductSchema = new MongooseSchema27(
|
|
|
2124
2441
|
{
|
|
2125
2442
|
couponId: {
|
|
2126
2443
|
required: true,
|
|
2127
|
-
type:
|
|
2444
|
+
type: mongoose31.Schema.Types.ObjectId
|
|
2128
2445
|
},
|
|
2129
2446
|
productId: {
|
|
2130
2447
|
required: true,
|
|
2131
|
-
type:
|
|
2448
|
+
type: mongoose31.Schema.Types.ObjectId
|
|
2132
2449
|
},
|
|
2133
2450
|
vendorCouponId: {
|
|
2134
2451
|
required: false,
|
|
2135
|
-
type:
|
|
2452
|
+
type: mongoose31.Schema.Types.ObjectId
|
|
2136
2453
|
},
|
|
2137
2454
|
vendorId: {
|
|
2138
2455
|
ref: "Vendor",
|
|
2139
2456
|
required: true,
|
|
2140
|
-
type:
|
|
2457
|
+
type: mongoose31.Schema.Types.ObjectId
|
|
2141
2458
|
}
|
|
2142
2459
|
},
|
|
2143
2460
|
{ _id: false }
|
|
@@ -2159,7 +2476,7 @@ var couponParticipantUserSchema = new MongooseSchema27(
|
|
|
2159
2476
|
userId: {
|
|
2160
2477
|
ref: "User",
|
|
2161
2478
|
required: true,
|
|
2162
|
-
type:
|
|
2479
|
+
type: mongoose31.Schema.Types.ObjectId
|
|
2163
2480
|
}
|
|
2164
2481
|
},
|
|
2165
2482
|
{ timestamps: true }
|
|
@@ -2191,7 +2508,7 @@ var couponDataSchema = new MongooseSchema27(
|
|
|
2191
2508
|
},
|
|
2192
2509
|
{ timestamps: true }
|
|
2193
2510
|
);
|
|
2194
|
-
var
|
|
2511
|
+
var schema23 = new MongooseSchema27(
|
|
2195
2512
|
{
|
|
2196
2513
|
active: { default: true, required: true, type: Boolean },
|
|
2197
2514
|
couponData: { default: [], required: false, type: [couponDataSchema] },
|
|
@@ -2203,9 +2520,9 @@ var schema19 = new MongooseSchema27(
|
|
|
2203
2520
|
},
|
|
2204
2521
|
{ timestamps: true }
|
|
2205
2522
|
);
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
var CouponModel =
|
|
2523
|
+
schema23.index({ active: 1, deletedAt: 1, "owner.userId": 1 });
|
|
2524
|
+
schema23.index({ "couponData.participantUsers.userId": 1 });
|
|
2525
|
+
var CouponModel = mongoose31.models.Coupon || mongoose31.model("Coupon", schema23);
|
|
2209
2526
|
|
|
2210
2527
|
// src/service/promoCode/constants.ts
|
|
2211
2528
|
var ACTIVE_NOT_DELETED_FILTER = {
|
|
@@ -2404,8 +2721,9 @@ async function getPayingStripePlanFor(userId, now, payingPlans) {
|
|
|
2404
2721
|
if (stripe == null || stripe.subscriptionId == null) {
|
|
2405
2722
|
return { hasSubscription: false, plan: null, validTypes };
|
|
2406
2723
|
}
|
|
2407
|
-
const hasActiveStatus = stripe.status === EnumSubscriptionStatus2.ACTIVE
|
|
2408
|
-
|
|
2724
|
+
const hasActiveStatus = stripe.status === EnumSubscriptionStatus2.ACTIVE;
|
|
2725
|
+
const paidThrough = stripe.endDate ? new Date(stripe.endDate).getTime() : Number.NaN;
|
|
2726
|
+
if (!hasActiveStatus || !Number.isFinite(paidThrough) || paidThrough <= now.getTime() || stripe.currentPlan == null) {
|
|
2409
2727
|
return { hasSubscription: false, plan: null, validTypes };
|
|
2410
2728
|
}
|
|
2411
2729
|
const plan = payingPlans.has(stripe.currentPlan) ? stripe.currentPlan : null;
|
|
@@ -2476,16 +2794,22 @@ async function isEligibleReferredVendor({
|
|
|
2476
2794
|
async function notifyAffiliateOwnerOfSubscriptionReward({
|
|
2477
2795
|
affiliateId,
|
|
2478
2796
|
affiliateOwnerUserId,
|
|
2479
|
-
|
|
2480
|
-
rewardValue
|
|
2797
|
+
awards
|
|
2481
2798
|
}) {
|
|
2799
|
+
if (awards.length === 0) {
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
const totalPoints = awards.reduce((sum, award) => sum + award.rewardValue, 0);
|
|
2803
|
+
const resourceNames = awards.map((award) => award.resourceName);
|
|
2804
|
+
const pointLabel = totalPoints === 1 ? "point" : "points";
|
|
2805
|
+
const message = awards.length === 1 ? `You earned ${totalPoints} ${pointLabel}! Your referred vendor "${resourceNames[0]}" has an active subscription.` : `You earned ${totalPoints} ${pointLabel}! ${awards.length} of your referred vendors have an active subscription.`;
|
|
2482
2806
|
const payload = {
|
|
2483
2807
|
data: {
|
|
2484
2808
|
resourceId: String(affiliateId),
|
|
2485
|
-
resourceName,
|
|
2809
|
+
resourceName: resourceNames.join(", "),
|
|
2486
2810
|
resourceType: EnumNotificationResourceType3.AFFILIATE_REWARD_RECEIVED
|
|
2487
2811
|
},
|
|
2488
|
-
message
|
|
2812
|
+
message,
|
|
2489
2813
|
title: "Affiliate points earned",
|
|
2490
2814
|
type: EnumNotificationType2.SYSTEM,
|
|
2491
2815
|
userIds: [affiliateOwnerUserId]
|
|
@@ -2537,15 +2861,12 @@ async function tryAwardSubscriptionReward({
|
|
|
2537
2861
|
}
|
|
2538
2862
|
).exec();
|
|
2539
2863
|
if (updateResult.modifiedCount === 0) {
|
|
2540
|
-
return
|
|
2864
|
+
return null;
|
|
2541
2865
|
}
|
|
2542
|
-
|
|
2543
|
-
affiliateId: affiliate._id,
|
|
2544
|
-
affiliateOwnerUserId: affiliate.owner.userId,
|
|
2866
|
+
return {
|
|
2545
2867
|
resourceName: resource.resourceName,
|
|
2546
2868
|
rewardValue: reward.rewardValue
|
|
2547
|
-
}
|
|
2548
|
-
return "awarded";
|
|
2869
|
+
};
|
|
2549
2870
|
}
|
|
2550
2871
|
async function processAffiliateVendorReferral({
|
|
2551
2872
|
affiliate,
|
|
@@ -2559,14 +2880,14 @@ async function processAffiliateVendorReferral({
|
|
|
2559
2880
|
resourceOwnerUserId: resource.resourceOwner.userId
|
|
2560
2881
|
});
|
|
2561
2882
|
if (!vendorEligible) {
|
|
2562
|
-
return
|
|
2883
|
+
return null;
|
|
2563
2884
|
}
|
|
2564
2885
|
const rewardType = await mapVendorLicenceToSubscriptionRewardType(
|
|
2565
2886
|
resource.resourceOwner.userId,
|
|
2566
2887
|
now
|
|
2567
2888
|
);
|
|
2568
2889
|
if (!rewardType) {
|
|
2569
|
-
return
|
|
2890
|
+
return null;
|
|
2570
2891
|
}
|
|
2571
2892
|
return tryAwardSubscriptionReward({
|
|
2572
2893
|
affiliate,
|
|
@@ -2582,8 +2903,9 @@ async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new
|
|
|
2582
2903
|
const affiliates = await findAffiliatesWithActiveVendorReferrals();
|
|
2583
2904
|
let awarded = 0;
|
|
2584
2905
|
let skipped = 0;
|
|
2585
|
-
const seenPairs = /* @__PURE__ */ new Set();
|
|
2586
2906
|
for (const affiliate of affiliates) {
|
|
2907
|
+
const awards = [];
|
|
2908
|
+
const seenPairs = /* @__PURE__ */ new Set();
|
|
2587
2909
|
for (const resource of affiliate.affiliateResources) {
|
|
2588
2910
|
if (!isEligibleVendorResource(resource)) {
|
|
2589
2911
|
continue;
|
|
@@ -2593,19 +2915,27 @@ async function awardAffiliateVendorSubscriptionRewards(now = /* @__PURE__ */ new
|
|
|
2593
2915
|
continue;
|
|
2594
2916
|
}
|
|
2595
2917
|
seenPairs.add(pairKey);
|
|
2596
|
-
const
|
|
2918
|
+
const award = await processAffiliateVendorReferral({
|
|
2597
2919
|
affiliate,
|
|
2598
2920
|
createdAt,
|
|
2599
2921
|
now,
|
|
2600
2922
|
period,
|
|
2601
2923
|
resource
|
|
2602
2924
|
});
|
|
2603
|
-
if (
|
|
2925
|
+
if (award) {
|
|
2604
2926
|
awarded += 1;
|
|
2927
|
+
awards.push(award);
|
|
2605
2928
|
} else {
|
|
2606
2929
|
skipped += 1;
|
|
2607
2930
|
}
|
|
2608
2931
|
}
|
|
2932
|
+
if (awards.length > 0) {
|
|
2933
|
+
await notifyAffiliateOwnerOfSubscriptionReward({
|
|
2934
|
+
affiliateId: affiliate._id,
|
|
2935
|
+
affiliateOwnerUserId: affiliate.owner.userId,
|
|
2936
|
+
awards
|
|
2937
|
+
});
|
|
2938
|
+
}
|
|
2609
2939
|
}
|
|
2610
2940
|
return { awarded, skipped };
|
|
2611
2941
|
}
|
|
@@ -2631,7 +2961,7 @@ function normalizeAffiliatePromoCodes(promoCodes) {
|
|
|
2631
2961
|
}
|
|
2632
2962
|
|
|
2633
2963
|
// src/service/database.ts
|
|
2634
|
-
import
|
|
2964
|
+
import mongoose32 from "mongoose";
|
|
2635
2965
|
var connectToDatabase = async ({
|
|
2636
2966
|
appName,
|
|
2637
2967
|
dbName,
|
|
@@ -2644,7 +2974,7 @@ var connectToDatabase = async ({
|
|
|
2644
2974
|
// Fallback to MongoDB Atlas connection string
|
|
2645
2975
|
`mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
|
|
2646
2976
|
);
|
|
2647
|
-
await
|
|
2977
|
+
await mongoose32.connect(mongoUri);
|
|
2648
2978
|
const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
|
|
2649
2979
|
console.log(
|
|
2650
2980
|
`${connectionType} connected from server/src/service/database.ts`
|
|
@@ -2657,7 +2987,7 @@ var connectToDatabase = async ({
|
|
|
2657
2987
|
|
|
2658
2988
|
// src/types/index.ts
|
|
2659
2989
|
import express from "express";
|
|
2660
|
-
import
|
|
2990
|
+
import mongoose33 from "mongoose";
|
|
2661
2991
|
var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
|
|
2662
2992
|
EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
|
|
2663
2993
|
EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
|
|
@@ -2712,7 +3042,12 @@ async function notifyUsers({
|
|
|
2712
3042
|
}
|
|
2713
3043
|
|
|
2714
3044
|
// src/service/updateAdStatus.ts
|
|
2715
|
-
import {
|
|
3045
|
+
import {
|
|
3046
|
+
EnumAdApprovalStatus as EnumAdApprovalStatus3,
|
|
3047
|
+
EnumAdBookingSlotKind as EnumAdBookingSlotKind3,
|
|
3048
|
+
EnumAdPaymentStatus as EnumAdPaymentStatus2,
|
|
3049
|
+
EnumAdStatus as EnumAdStatus2
|
|
3050
|
+
} from "@timardex/cluemart-shared";
|
|
2716
3051
|
async function updateAdStatuses() {
|
|
2717
3052
|
const now = /* @__PURE__ */ new Date();
|
|
2718
3053
|
const invalidResult = await AdModel.updateMany(
|
|
@@ -2730,11 +3065,36 @@ async function updateAdStatuses() {
|
|
|
2730
3065
|
{ end: { $lte: now }, status: { $ne: EnumAdStatus2.EXPIRED } },
|
|
2731
3066
|
{ $set: { status: EnumAdStatus2.EXPIRED } }
|
|
2732
3067
|
);
|
|
3068
|
+
const eligibleBooking = {
|
|
3069
|
+
$or: [
|
|
3070
|
+
{ bookingKind: { $exists: false } },
|
|
3071
|
+
{ bookingKind: null },
|
|
3072
|
+
{
|
|
3073
|
+
approvalStatus: EnumAdApprovalStatus3.APPROVED,
|
|
3074
|
+
bookingKind: EnumAdBookingSlotKind3.RESERVED
|
|
3075
|
+
},
|
|
3076
|
+
{
|
|
3077
|
+
approvalStatus: EnumAdApprovalStatus3.APPROVED,
|
|
3078
|
+
bookingKind: EnumAdBookingSlotKind3.PAID,
|
|
3079
|
+
paymentStatus: EnumAdPaymentStatus2.PAID
|
|
3080
|
+
}
|
|
3081
|
+
]
|
|
3082
|
+
};
|
|
3083
|
+
const awaitingApprovalResult = await AdModel.updateMany(
|
|
3084
|
+
{
|
|
3085
|
+
$nor: eligibleBooking.$or,
|
|
3086
|
+
bookingKind: { $in: Object.values(EnumAdBookingSlotKind3) },
|
|
3087
|
+
end: { $gt: now },
|
|
3088
|
+
status: EnumAdStatus2.ACTIVE
|
|
3089
|
+
},
|
|
3090
|
+
{ $set: { status: EnumAdStatus2.PAUSED } }
|
|
3091
|
+
);
|
|
2733
3092
|
const activeResult = await AdModel.updateMany(
|
|
2734
3093
|
{
|
|
2735
3094
|
end: { $gt: now },
|
|
2736
3095
|
start: { $lte: now },
|
|
2737
|
-
status: { $ne: EnumAdStatus2.ACTIVE }
|
|
3096
|
+
status: { $ne: EnumAdStatus2.ACTIVE },
|
|
3097
|
+
...eligibleBooking
|
|
2738
3098
|
},
|
|
2739
3099
|
{ $set: { status: EnumAdStatus2.ACTIVE } }
|
|
2740
3100
|
);
|
|
@@ -2743,20 +3103,20 @@ async function updateAdStatuses() {
|
|
|
2743
3103
|
{ $set: { status: EnumAdStatus2.PAUSED } }
|
|
2744
3104
|
);
|
|
2745
3105
|
console.log(
|
|
2746
|
-
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
3106
|
+
`\u2705 Ad statuses updated: invalid=${invalidResult.modifiedCount}, expired=${expiredResult.modifiedCount}, awaitingApproval=${awaitingApprovalResult.modifiedCount}, active=${activeResult.modifiedCount}, paused=${pausedResult.modifiedCount}`
|
|
2747
3107
|
);
|
|
2748
3108
|
}
|
|
2749
3109
|
|
|
2750
3110
|
// src/service/objectIdToString.ts
|
|
2751
|
-
import
|
|
3111
|
+
import mongoose34 from "mongoose";
|
|
2752
3112
|
function isValidObjectId(value) {
|
|
2753
|
-
return
|
|
3113
|
+
return mongoose34.Types.ObjectId.isValid(value);
|
|
2754
3114
|
}
|
|
2755
3115
|
function convertObjectIdsToStrings(obj) {
|
|
2756
3116
|
if (obj === null || obj === void 0) {
|
|
2757
3117
|
return obj;
|
|
2758
3118
|
}
|
|
2759
|
-
if (obj instanceof
|
|
3119
|
+
if (obj instanceof mongoose34.Types.ObjectId) {
|
|
2760
3120
|
return obj.toString();
|
|
2761
3121
|
}
|
|
2762
3122
|
if (obj instanceof Date) {
|
|
@@ -3423,42 +3783,122 @@ async function checkOwnerHasLicence({
|
|
|
3423
3783
|
}
|
|
3424
3784
|
|
|
3425
3785
|
// src/service/license/compliance/vendor.ts
|
|
3426
|
-
async function
|
|
3786
|
+
async function findUserVendor(userId, logLabel) {
|
|
3787
|
+
const user = await UserModel.findById(userId).select("vendor").lean().exec();
|
|
3788
|
+
if (!user?.vendor) {
|
|
3789
|
+
console.warn(`[${logLabel}] No vendor found for userId=${userId}`);
|
|
3790
|
+
return null;
|
|
3791
|
+
}
|
|
3792
|
+
const vendor = await VendorModel.findOne({
|
|
3793
|
+
_id: user.vendor,
|
|
3794
|
+
active: true,
|
|
3795
|
+
deletedAt: null,
|
|
3796
|
+
"owner.userId": userId
|
|
3797
|
+
}).lean().exec();
|
|
3798
|
+
if (!vendor) {
|
|
3799
|
+
console.warn(
|
|
3800
|
+
`[${logLabel}] Vendor not found for id=${user.vendor}, userId=${userId}`
|
|
3801
|
+
);
|
|
3802
|
+
return null;
|
|
3803
|
+
}
|
|
3804
|
+
return vendor;
|
|
3805
|
+
}
|
|
3806
|
+
async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
3807
|
+
const updateData = {};
|
|
3808
|
+
updateData.availability = {
|
|
3809
|
+
corporate: false,
|
|
3810
|
+
private: false,
|
|
3811
|
+
school: false
|
|
3812
|
+
};
|
|
3813
|
+
updateData.products = {
|
|
3814
|
+
active: false,
|
|
3815
|
+
productsList: vendor.products?.productsList ?? []
|
|
3816
|
+
};
|
|
3817
|
+
updateData.calendar = {
|
|
3818
|
+
active: false,
|
|
3819
|
+
calendarData: vendor.calendar?.calendarData ?? []
|
|
3820
|
+
};
|
|
3821
|
+
updateData.downgradeSnapshot = {
|
|
3822
|
+
availability: vendor.availability,
|
|
3823
|
+
calendarActive: vendor.calendar?.active,
|
|
3824
|
+
productsActive: vendor.products?.active
|
|
3825
|
+
};
|
|
3826
|
+
updateData.images = (vendor.images ?? []).map((image, index) => ({
|
|
3827
|
+
...image,
|
|
3828
|
+
active: index < 6
|
|
3829
|
+
}));
|
|
3830
|
+
const result = await VendorModel.updateOne(
|
|
3831
|
+
{
|
|
3832
|
+
_id: vendor._id,
|
|
3833
|
+
active: true,
|
|
3834
|
+
deletedAt: null,
|
|
3835
|
+
"owner.userId": ownerUserId
|
|
3836
|
+
},
|
|
3837
|
+
{ $set: updateData }
|
|
3838
|
+
);
|
|
3839
|
+
return (result?.matchedCount ?? 0) > 0;
|
|
3840
|
+
}
|
|
3841
|
+
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
3842
|
+
const isStandardVendor = licenceType === EnumUserLicence9.STANDARD_VENDOR;
|
|
3843
|
+
if (!isStandardVendor) {
|
|
3844
|
+
return;
|
|
3845
|
+
}
|
|
3427
3846
|
try {
|
|
3428
|
-
const
|
|
3429
|
-
if (!
|
|
3430
|
-
console.warn(`[updateVendor] No vendor found for userId=${userId}`);
|
|
3847
|
+
const vendor = await findUserVendor(userId, "downgradeVendorProFeatures");
|
|
3848
|
+
if (!vendor) {
|
|
3431
3849
|
return;
|
|
3432
3850
|
}
|
|
3433
|
-
|
|
3851
|
+
await applyVendorDowngrade(vendor, userId);
|
|
3852
|
+
} catch (error) {
|
|
3853
|
+
console.error("[downgradeVendorProFeatures] Failed:", error);
|
|
3854
|
+
throw error;
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
async function applyVendorRestore(vendor, ownerUserId) {
|
|
3858
|
+
const updateData = {};
|
|
3859
|
+
const snapshot = vendor.downgradeSnapshot;
|
|
3860
|
+
updateData.availability = {
|
|
3861
|
+
corporate: snapshot?.availability?.corporate ?? true,
|
|
3862
|
+
private: snapshot?.availability?.private ?? true,
|
|
3863
|
+
school: snapshot?.availability?.school ?? true
|
|
3864
|
+
};
|
|
3865
|
+
updateData.products = {
|
|
3866
|
+
active: snapshot?.productsActive ?? true,
|
|
3867
|
+
productsList: vendor.products?.productsList ?? []
|
|
3868
|
+
};
|
|
3869
|
+
updateData.calendar = {
|
|
3870
|
+
active: snapshot?.calendarActive ?? true,
|
|
3871
|
+
calendarData: vendor.calendar?.calendarData ?? []
|
|
3872
|
+
};
|
|
3873
|
+
updateData.images = (vendor.images ?? []).map((image) => ({
|
|
3874
|
+
...image,
|
|
3875
|
+
active: true
|
|
3876
|
+
}));
|
|
3877
|
+
const result = await VendorModel.updateOne(
|
|
3878
|
+
{
|
|
3879
|
+
_id: vendor._id,
|
|
3880
|
+
active: true,
|
|
3881
|
+
deletedAt: null,
|
|
3882
|
+
"owner.userId": ownerUserId
|
|
3883
|
+
},
|
|
3884
|
+
{ $set: updateData }
|
|
3885
|
+
);
|
|
3886
|
+
return (result?.matchedCount ?? 0) > 0;
|
|
3887
|
+
}
|
|
3888
|
+
async function restoreVendorProFeatures(userId, licenceType) {
|
|
3889
|
+
const isProVendor = licenceType === EnumUserLicence9.PRO_VENDOR || licenceType === EnumUserLicence9.PRO_PLUS_VENDOR;
|
|
3890
|
+
if (!isProVendor) {
|
|
3891
|
+
return;
|
|
3892
|
+
}
|
|
3893
|
+
try {
|
|
3894
|
+
const vendor = await findUserVendor(userId, "restoreVendorProFeatures");
|
|
3434
3895
|
if (!vendor) {
|
|
3435
|
-
console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
|
|
3436
3896
|
return;
|
|
3437
3897
|
}
|
|
3438
|
-
|
|
3439
|
-
const isStandardVendor = licenceType === EnumUserLicence9.STANDARD_VENDOR;
|
|
3440
|
-
if (isStandardVendor) {
|
|
3441
|
-
updateData.availability = {
|
|
3442
|
-
corporate: false,
|
|
3443
|
-
private: false,
|
|
3444
|
-
school: false
|
|
3445
|
-
};
|
|
3446
|
-
updateData.products = {
|
|
3447
|
-
active: false,
|
|
3448
|
-
productsList: vendor.products?.productsList ?? []
|
|
3449
|
-
};
|
|
3450
|
-
updateData.calendar = {
|
|
3451
|
-
active: false,
|
|
3452
|
-
calendarData: vendor.calendar?.calendarData ?? []
|
|
3453
|
-
};
|
|
3454
|
-
}
|
|
3455
|
-
updateData.images = (vendor.images ?? []).map((image, index) => ({
|
|
3456
|
-
...image,
|
|
3457
|
-
active: isStandardVendor ? index < 6 : true
|
|
3458
|
-
}));
|
|
3459
|
-
await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
|
|
3898
|
+
await applyVendorRestore(vendor, userId);
|
|
3460
3899
|
} catch (error) {
|
|
3461
|
-
console.error("[
|
|
3900
|
+
console.error("[restoreVendorProFeatures] Failed:", error);
|
|
3901
|
+
throw error;
|
|
3462
3902
|
}
|
|
3463
3903
|
}
|
|
3464
3904
|
var vendorLicences = [
|
|
@@ -3468,14 +3908,25 @@ var vendorLicences = [
|
|
|
3468
3908
|
];
|
|
3469
3909
|
function isProtectedByCurrentStripeSubscription(user, licenceType, now) {
|
|
3470
3910
|
const stripe = user.stripe;
|
|
3471
|
-
if (!stripe
|
|
3911
|
+
if (!stripe || stripe.currentPlan !== licenceType) {
|
|
3472
3912
|
return false;
|
|
3473
3913
|
}
|
|
3474
|
-
|
|
3914
|
+
const gracePeriodEndsAt = stripe.paymentGracePeriodEndsAt ? dayjs4(stripe.paymentGracePeriodEndsAt) : null;
|
|
3915
|
+
const hasActivePaymentGracePeriod = (stripe.status === EnumSubscriptionStatus3.PAST_DUE || stripe.status === EnumSubscriptionStatus3.INACTIVE) && Boolean(stripe.paymentGraceSubscriptionId) && (!stripe.subscriptionId || stripe.subscriptionId === stripe.paymentGraceSubscriptionId) && gracePeriodEndsAt !== null && gracePeriodEndsAt.isValid() && gracePeriodEndsAt.isAfter(now);
|
|
3916
|
+
if (hasActivePaymentGracePeriod) {
|
|
3475
3917
|
return true;
|
|
3476
3918
|
}
|
|
3919
|
+
if (!stripe.subscriptionId) {
|
|
3920
|
+
return false;
|
|
3921
|
+
}
|
|
3922
|
+
if (stripe.status !== EnumSubscriptionStatus3.ACTIVE) {
|
|
3923
|
+
return false;
|
|
3924
|
+
}
|
|
3925
|
+
if (!stripe.endDate) {
|
|
3926
|
+
return false;
|
|
3927
|
+
}
|
|
3477
3928
|
const paidThrough = dayjs4(stripe.endDate);
|
|
3478
|
-
return
|
|
3929
|
+
return paidThrough.isValid() && paidThrough.isAfter(now);
|
|
3479
3930
|
}
|
|
3480
3931
|
async function handleVendorLicenceCompliance(user, now) {
|
|
3481
3932
|
if (!user.licences || !user.vendor) {
|
|
@@ -3524,10 +3975,10 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
3524
3975
|
if (!expiredProLicence || !vendor || hasValidProLicence) {
|
|
3525
3976
|
return;
|
|
3526
3977
|
}
|
|
3527
|
-
await
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3978
|
+
const downgraded = await applyVendorDowngrade(vendor, user._id);
|
|
3979
|
+
if (!downgraded) {
|
|
3980
|
+
return;
|
|
3981
|
+
}
|
|
3531
3982
|
const payload = {
|
|
3532
3983
|
data: {
|
|
3533
3984
|
resourceId: String(vendor._id),
|
|
@@ -3550,9 +4001,23 @@ async function vendorOwnerHasProLicence(vendorId) {
|
|
|
3550
4001
|
if (!vendor) {
|
|
3551
4002
|
return false;
|
|
3552
4003
|
}
|
|
3553
|
-
const owner = await UserModel.findById(vendor.owner.userId, {
|
|
4004
|
+
const owner = await UserModel.findById(vendor.owner.userId, {
|
|
4005
|
+
licences: 1,
|
|
4006
|
+
stripe: 1
|
|
4007
|
+
}).lean().exec();
|
|
4008
|
+
if (!owner) {
|
|
4009
|
+
return false;
|
|
4010
|
+
}
|
|
4011
|
+
const now = dayjs4();
|
|
4012
|
+
const effectiveVendorLicences = owner.licences?.filter(
|
|
4013
|
+
(licence) => licence?.licenceType && (dayjs4(licence.expiryDate).isAfter(now) || isProtectedByCurrentStripeSubscription(
|
|
4014
|
+
owner,
|
|
4015
|
+
licence.licenceType,
|
|
4016
|
+
now
|
|
4017
|
+
))
|
|
4018
|
+
);
|
|
3554
4019
|
const highestVendorLicence = getHighestLicenceForCategory(
|
|
3555
|
-
|
|
4020
|
+
effectiveVendorLicences,
|
|
3556
4021
|
"vendor" /* VENDOR */
|
|
3557
4022
|
);
|
|
3558
4023
|
return highestVendorLicence !== null && licencePriority[highestVendorLicence] >= licencePriority[EnumUserLicence9.PRO_VENDOR];
|
|
@@ -3969,8 +4434,13 @@ async function remindUsersAboutLicenseExpiration() {
|
|
|
3969
4434
|
}
|
|
3970
4435
|
export {
|
|
3971
4436
|
ACTIVE_NOT_DELETED_FILTER,
|
|
4437
|
+
AD_BILLING_CATALOG_COLLECTION_NAME,
|
|
3972
4438
|
APP_SETTINGS_ID,
|
|
4439
|
+
AdBillingCatalogModel,
|
|
4440
|
+
AdBookingModel,
|
|
4441
|
+
AdImpressionModel,
|
|
3973
4442
|
AdModel,
|
|
4443
|
+
AdSettingsModel,
|
|
3974
4444
|
AffiliateModel,
|
|
3975
4445
|
AppSettingModel,
|
|
3976
4446
|
BILLING_CATALOG_COLLECTION_NAME,
|
|
@@ -3980,6 +4450,7 @@ export {
|
|
|
3980
4450
|
ChatReportModel,
|
|
3981
4451
|
ContactDetailsSchema,
|
|
3982
4452
|
CouponModel,
|
|
4453
|
+
DEFAULT_AD_SETTINGS,
|
|
3983
4454
|
EnumPubSubEvents,
|
|
3984
4455
|
EventInfoModel,
|
|
3985
4456
|
EventModel,
|
|
@@ -4018,6 +4489,7 @@ export {
|
|
|
4018
4489
|
createLicenceObject,
|
|
4019
4490
|
dateTimeSchema2 as dateTimeSchema,
|
|
4020
4491
|
didRemoveAnyEventDates,
|
|
4492
|
+
downgradeVendorProFeatures,
|
|
4021
4493
|
ensureUserLicenseCompliance,
|
|
4022
4494
|
ensureUserLicenseComplianceForUser,
|
|
4023
4495
|
eventLicences,
|
|
@@ -4046,7 +4518,7 @@ export {
|
|
|
4046
4518
|
locationGeoSchema,
|
|
4047
4519
|
locationsSchema,
|
|
4048
4520
|
mapVendorLicenceToSubscriptionRewardType,
|
|
4049
|
-
|
|
4521
|
+
mongoose33 as mongoose,
|
|
4050
4522
|
normalizeAffiliatePromoCodes,
|
|
4051
4523
|
normalizePromoCode,
|
|
4052
4524
|
notifyUsers,
|
|
@@ -4061,7 +4533,9 @@ export {
|
|
|
4061
4533
|
remindUsersAboutLicenseExpiration,
|
|
4062
4534
|
replaceUserLicenceWithObject,
|
|
4063
4535
|
resourceRelationsSchema,
|
|
4536
|
+
restoreVendorProFeatures,
|
|
4064
4537
|
saveNotificationsInDb,
|
|
4538
|
+
schemaAdresource,
|
|
4065
4539
|
sendDeactivationNotification,
|
|
4066
4540
|
sendLicenseReminder,
|
|
4067
4541
|
sendPushNotifications,
|
|
@@ -4073,7 +4547,6 @@ export {
|
|
|
4073
4547
|
updateAllEventDateTimeStatuses,
|
|
4074
4548
|
updateRelationDatesToUnavailable,
|
|
4075
4549
|
updateSingleDateTimeStatus,
|
|
4076
|
-
updateVendorBasedOnUserLicense,
|
|
4077
4550
|
upgradeUserToLicence,
|
|
4078
4551
|
userLicenseSchema,
|
|
4079
4552
|
vendorLicences,
|